如何在php中保存编辑后的图像
我有一个图像,我使用php的“imagettftext”函数在这个图像上写了一些文本。现在我不知道它将如何保存自动如何在php中保存编辑后的图像,php,html,css,image,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 = imagecoloralloc
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()
函数的文档
通过将文件名作为第二个参数传递,它将图像保存到文件中,例如:
imagepng($im, "path/to/save/image/in.png");
如果您查看文档,您会发现您可以提供一个文件名。这将把图像保存到磁盘上
<?php
// Save the image as 'simpletext.png'
imagepng($im, 'simpletext.png');
// Free up memory
imagedestroy($im);
?>
这是一个关于如何保存图像的示例