Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.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 imagecreatefrompng使导入的图像块为ish?_Php_Imagecreatefrompng - Fatal编程技术网

Php imagecreatefrompng使导入的图像块为ish?

Php imagecreatefrompng使导入的图像块为ish?,php,imagecreatefrompng,Php,Imagecreatefrompng,我试图使用以下PHP将随机生成的文本文件应用于图像。(我现在只使用随机图像。) 可能是阿尔法混合问题。在保存图像之前,请尝试添加以下内容: imagealphablending($im, true); imagesavealpha($im, true); 如果注释掉$im=imagecreatefrompng(“test.png”)之间的所有内容,生成的图像会发生什么变化;和imagepng($im)@如上图所示(以及您所建议的),vascowhite的注释只会产生相同的结果——只是现在文

我试图使用以下PHP将随机生成的文本文件应用于图像。(我现在只使用随机图像。)


可能是阿尔法混合问题。在保存图像之前,请尝试添加以下内容:

imagealphablending($im, true); 
imagesavealpha($im, true); 

如果注释掉$im=imagecreatefrompng(“test.png”)之间的所有内容,生成的图像会发生什么变化;和imagepng($im)@如上图所示(以及您所建议的),vascowhite的注释只会产生相同的结果——只是现在文本也没有写入到图像上。您刚才所做的是从问题中删除6行代码。你试过用不同的图像吗?有一个完全不同的问题,但这也解决了我的一些东西!荣誉
<?php
header ("Content-type: image/png");

$textfile = "quote.txt";
$quotes = array();
if(file_exists($textfile)){
$quotes = file($textfile);
srand ((float) microtime() * 10000000);
$string = $quotes[array_rand($quotes)];
$string = substr($string,0,strlen($string)-1);
}
else{
$string = "No 'Quote' available at this time.";
}


//$string = "your text";
// try changing this as well
$font = 4;
$width = imagefontwidth($font) * strlen($string) ;
$height = imagefontheight($font) ;
$im = imagecreatefrompng("test.png");
//$x = imagesx($im) - $width ;
//$y = imagesy($im) - $height;
//$backgroundColor = imagecolorallocate ($im, 255, 255, 255);
//$textColor = imagecolorallocate ($im, 0, 0,0);
//imagestring ($im, $font, $x, $y,  $string, $textColor);
imagepng($im);
ImageDestroy($im);
?>
imagealphablending($im, true); 
imagesavealpha($im, true);