将输出图像保存到不同的目录中,使用新的文件名和扩展名 [英] Save the output image into a different directory, with a new filename and extension

查看:116
本文介绍了将输出图像保存到不同的目录中,使用新的文件名和扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在image.php文件中有此代码,该文件将创建新的GD图像流并输出图像:

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);

这是我的示例图:


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

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

目录 - > / root / template / images

directory -> /root/template/images

如何将输出的image.php图像保存到/ images目录中,具有不同的文件名和扩展名,如file.png

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

推荐答案


文件名参数

保存文件的路径。如果没有设置或为NULL,原始图像流
将直接输出。

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

我找到了一个解决方案,只需添加一个第二个参数文件名到 imagepng()功能:

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

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

这篇关于将输出图像保存到不同的目录中,使用新的文件名和扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆