dqyl2374
dqyl2374
2012-03-24 19:34
浏览 52
已采纳

imagegif()函数无法正常工作

Hello everyone I am trying to write a string on image during runtime and for this purpose I am using imagestring from GD, but am not getting the required output instead its giving met his error:

imagegif(): Unable to open 'temp/textImage.gif' for writing: No such file or directory in … on line 157 Warning:

However this same code was working fine with imagefttext() function, but as my hosting provider heroku does not support freetype library so that’s why ive to switch.

        $message = “Hello World”;
        //Image Processing:
        $imageUrl = "image.gif";
        $imageId = imagecreatefromgif($imageUrl);

        $angle = 0;
        $xCord = 4;
        $yCord = 40;
        $imageColor = imagecolorallocate($imageId, 0, 0, 0);
        $fontUrl = "GOTHIC.TTF";
        $imageText = "HELOOOO";
        $imageTextLnght = strlen($imageText);
        $fontSize = (500 / $imageTextLnght) + 5;
        $imageFont = 1;

//imagefttext($imageId, $fontSize, $angle, $xCord, $yCord, $imageColor, $fontUrl, $imageText);
        imagestring($imageId, 5, $xCord, $yCord, $imageText, $imageColor);
        //header('Content-Type: image/gif');

        //Saving Image With Text:
        $textImage = 'temp/textImage.gif';
        imagegif($imageId, $textImage);
        imagedestroy($imageId);

Kindly help me with this: Thankyou

图片转代码服务由CSDN问答提供 功能建议

大家好我想在运行时在图像上写一个字符串,为此我正在使用 imagestring 来自GD的,但是没有得到所需的输出而是它的给出了他的错误:

imagegif():无法打开'temp / textImage.gif' 写作:第157行上没有这样的文件或目录警告:

但是这个相同的代码与 imagefttext()函数一起正常工作,但是 因为我的托管服务提供商 heroku 不支持freetype库,所以这就是我要切换的原因。

  $ message =“Hello World”; 
 // 图像处理:
 $ imageUrl =“image.gif”; 
 $ imageId = imagecreatefromgif($ imageUrl); 
 
 $ angle = 0; 
 $ xCord = 4; 
 $ yCord = 40; 
  $ imageColor = imagecolorallocate($ imageId,0,0,0); 
 $ fontUrl =“GOTHIC.TTF”; 
 $ imageText =“HELOOOO”; 
 $ imageTextLnght = strlen($  imageText); 
 $ fontSize =(500 / $ imageTextLnght)+ 5; 
 $ imageFont = 1; 
 
 // imagefttext($ imageId,$ fontSize,$ angle,$ xCord,$ yCord,$ imageColor,  $ fontUrl,$ imageText); 
 imagestring($ imageId,5,$ xCord,$ yCord,$ imageText,$ imageColor); 
 // header('Content-Type:image / gif'); 
 
  //用文本保存图像:
 $ textImage ='temp / textImage.gif'; 
 imagegif($ imageId,$ textImage); 
 imagedestroy($ imageId); 
   \  n 
 

请帮助我: Thankyou

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dorisdong0514
    dorisdong0514 2012-03-24 19:45
    已采纳

    Make sure that temp exists, or create it with mkdir.

    Usually the error Unable to open .. No such file or directory when trying to create a file means that the directory doesn't exist.

    点赞 评论

相关推荐