0

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
  • I've followed this answer but I get a "file.png" that have a 0 byte size on disk. "...can't open this picture because the file appears to be damaged, corrupted..." Commented May 19, 2015 at 17:22

1 Answer 1

0

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');
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.