Save the output image into a different directory, with a new filename and extension [duplicate]

做~自己de王妃 提交于 2020-01-06 14:59:06

问题


Let say I have this code in my "image.php" file that will create a new GD image stream and output an image:

header ('Content-Type: image/png');
$im = @imagecreatetruecolor(120, 20)
      or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);

Here's my sample diagram:

file -> /root/template/program/image.php

directory -> /root/template/images

How can I save the outputted image of "image.php" into the "/images" directory, with a different filename and extension like "file.png"?


回答1:


filename parameter
The path to save the file to. If not set or NULL, the raw image stream will be outputted directly.

I found a solution, just add a second parameter filename to the imagepng() function:

imagepng($im, '../images/file.png');


来源:https://stackoverflow.com/questions/30331812/save-the-output-image-into-a-different-directory-with-a-new-filename-and-extens

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!