Saving an image using the GD library

I’m running Linux and running Apache. I use the GD library for PHP.
Can’t save image by calling

imagePNG($image, '1.png');

The image is not saved. At least by name, this file is not located. What to do? Maybe something wrong in the settings?
Maybe the problem is in the library itself?
Full code:

$image = imagecreate(255, 255);
imagecolorallocate($image, 0, 0, 255);
$c = imagecolorallocate($image, 255, 255, 0);
imagestring($image, 4, 3, 1, 'iloveinukraine.com', $c);
header('Content-Type: image/png;');
imagePNG($image, '1.png');
imagedestroy($image);

Answer 1, authority 100%

If you just need to give to the client, then you can do this:

header('Content-Type: image/png;');
imagePNG($image);
imagedestroy($image);

In general, there is either a restriction with the rights to create files in this directory. By the way, the file must be created in the directory where your script is located.

And maybe I’m wrong, but try running the script without imagedestroy($image), it might delete the file as well.


Answer 2

Which Linux distribution? Maybe there is no libpng package or no php-gd at all 🙂

phpinfo show


Answer 3

you would specify an absolute path for the test … yes error log smoke, don’t be lazy to smoke.

imagePNG($image, '/tmp/1.png');

So, does it work?