我有一个图像,我使用 php“imagettftext”函数在该图像上写了一些文本。现在我不知道它如何自动保存。
header('Content-Type: image/png');
// Create the image
$im = imagecreatefromjpeg('image-1.jpg');
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
//imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'www.blockprintsonline.com';
// Replace path by your own font path
$font = 'arial.ttf';
list($width, $height, $type, $attr) = getimagesize($get_image);
$width1=$width*20/100;
$height1=$height*50/100;
$font_size=$width*4/100;
// Add some shadow to the text
//imagettftext($im, 30, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, $font_size, 0, $width1, $height1, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
最佳答案
如果要将图像保存到文件中,请查看 imagepng()
函数的文档 here .
通过传递文件名作为第二个参数,它将图像保存到文件中,例如:
imagepng($im, "path/to/save/image/in.png");
关于php - 如何在php中编辑后保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15361858/