9951 explained code solutions for 126 technologies


php-gdHow to save PNG image to file


$im = imagecreatetruecolor(400, 300);

# ...

imagepng($im, '/tmp/image.png');ctrl + c
imagepng

saves given image resource in PNG format

imagecreatetruecolor

creates true color GD image object with specified width & height

/tmp/image.png

path to file save image to


How to save PNG image to file, php gd

Usage example

<?php

$im = imagecreatetruecolor(400, 300);

$c_black = imageColorAllocate($im, 0,0,0);
$c_green = imageColorAllocate($im, 46,204,64);

imageellipse($im, 200, 150, 100, 100, $c_green);

imagepng($im, '/tmp/image.png');