php - 如何在php中编辑后保存图像

标签 php html css image

我有一个图像,我使用 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/

相关文章:

php - 无法运行 PHP::SVM

javascript - 对话框不关闭

javascript - 使用 CSS 或 JS 隐藏 a href 标签内的文本

php - 将CI 3与HMVC一起使用时无法加载库

php - MySQL:AND 运算符不起作用

java - 如果使用 ruby​​ on rails、python 或 java 可以做得更好,为什么还要使用 php 框架进行编程?

jquery - 使用列 View ext 时是否可以设置 fancyTree 的高度

html - 图像下的 css 转换问题

javascript - 如何防止离开时重新加载图像 "display: none"

javascript - 全宽并排div