我需要动态创建图像,即图像上的文本将是动态的。有什么方法可以用动态文本生成图像并保存它吗?我试过以下几种方法
<?php
header("Content-type: image/jpeg");
$imgPath = 'image.jpg';
$image = imagecreatefromjpeg($imgPath);
$color = imagecolorallocate($image, 255, 255, 255);
$string = "THIS TEXT IS DYNAMIC";
$fontSize = 3;
$x = 115;
$y = 185;
imagestring($image, $fontSize, $x, $y, $string, $color);
imagejpeg($image);
?>
但是它给我展示了文字的图像,但是它没有保存这个文字上的图像。我需要保存图片和上面写的文字
发布于 2014-10-24 16:22:46
使用函数签名
bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )
您需要使用第二个参数设置文件的路径。
这样做吧:
$saveToPath = dirname( __FILE__ ) . '/imageCache/myImageFile.jpg';
imagejpeg( $image, $saveToPath );
header( 'Content-Type: image/jpeg' );
readfile( $saveToPath );
https://stackoverflow.com/questions/26552020
复制相似问题