Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将字符串转换为图像时出现imagepng错误_Php_Image Processing - Fatal编程技术网

Php 将字符串转换为图像时出现imagepng错误

Php 将字符串转换为图像时出现imagepng错误,php,image-processing,Php,Image Processing,我正在将字符串转换为图像,并希望给出图像在元数据中的位置 我有这个代码,但这给了我错误 PHP警告:imagepng()要求参数1为资源,在 我犯了错误。请建议在文件夹名称的末尾添加斜杠:$tempDir='/temp/' 现在,您的图像被解释为temp56385145.png.png,而不是预期的temp/56385145.png.png(作为我所做测试中的一个示例数字) 另外,您可能还希望使用相对路径 即:$tempDir='temp/'或$tempDir='../temp/' 取决于代

我正在将字符串转换为图像,并希望给出图像在元数据中的位置

我有这个代码,但这给了我错误

PHP警告:imagepng()要求参数1为资源,在



我犯了错误。请建议在文件夹名称的末尾添加斜杠:
$tempDir='/temp/'

现在,您的图像被解释为
temp56385145.png.png
,而不是预期的
temp/56385145.png.png
(作为我所做测试中的一个示例数字)


另外,您可能还希望使用相对路径

即:
$tempDir='temp/'
$tempDir='../temp/'
取决于代码的执行位置


或者作为完整的系统路径:
$tempDir='/var/user/you/httpdocs/temp/

提示:$img从未使用过,除非在
imagepng()
@DenisV中,有一些复制/粘贴错误已更正。相同的错误添加斜杠
$tempDir='/temp/'-现在,您的图像被解释为
tempimage1888423092.png
,而不是解释错误的预期
temp/image1888423092.png
。如果您想将其作为答案发布,请告诉我;)我们只希望不会有人出现并从我的评论中获取信息。另外,您可能还希望使用相对路径或完整服务器路径。即:
$tempDir='temp/'
$tempDir='../temp/'取决于代码的执行位置。作为完整的系统路径:
$tempDir='/var/user/you/httpdocs/temp/@Fred ii-谢谢我尝试过。这是权限错误。现在我可以获取图像和位置,但完整的网页被该元图像阻止。不知道是什么问题
   <?php 

   $randimagefilename=rand(1000,100000000);

     $tempDir = '/temp';
     $fileName = $tempDir.$randimagefilename.'.png';



    header("Content-type: image/png");

    $string = 'hiiiiiiiiiiiiiiiiiiiiiiii how are you what is going on ';

  $font  = 8;
   $width  = imagefontwidth($font) * strlen($string);
   $height = imagefontheight($font);

 $image = imagecreatetruecolor ($width,$height);
  $white = imagecolorallocate ($image,255,255,255);
  $black = imagecolorallocate ($image,0,0,0);
 imagefill($image,0,0,$white);

  imagestring ($image,$font,0,0,$string,$black);

  imagepng($image, $fileName); 

imagedestroy($image);


    echo' <meta name="image_src" content="'.$fileName.'" />';
  ?>