Issue
I am created dynamic image using php and gd library as follows,
imagecopy ($iOut,$imgBuf[0],$left,$top,0,0,imagesx($imgBuf[0]),imagesy($imgBuf[0]));
imagedestroy ($imgBuf[0]);
ob_start();
imagepng($iOut);
printf('<img src="data:image/png;base64,%s"/>', base64_encode(ob_get_clean()));
How can I save this image to my local directory for further use. Any help please
Thanks
Solution
Look at the imagepng
documentation at http://php.net/manual/en/function.imagepng.php
You can pass in a second parameter to the function as
bool imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] )
So you can do
imagepng($iOut, $filename_to_save_to);
then you can simply display the image in the browser as
echo '<img src="' . $public_visible_path_to_saved_file . '"/>';
For this to work, i would choose the $filename_to_save_to
as a file in a subdirectory of your web root. E.g.
if your web root is /var/www
i would choose /var/www/uploaded_images/filename.png
then you can simply display it by specifying the $public_visible_path_to_saved_file
as uploaded_images/filename.png
Answered By - danishgoel Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.