Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert GD image back to binary data

Tags:

php

image

gd

I have a GD image resource created from imagecreatefromstring. After some image operations, I want to convert it back to binary data. How would I do this? Can't see any functions in the manual...

like image 445
DisgruntledGoat Avatar asked Feb 05 '10 14:02

DisgruntledGoat


2 Answers

Use imagejpeg, imagepng, or similar. Use output buffering if you want to dump the result to a string, rather than a file:

ob_start();
imagejpeg($im);
$image_string = ob_get_contents();
ob_end_flush();
like image 56
Annika Backstrom Avatar answered Oct 14 '22 22:10

Annika Backstrom


function image_data($gdimage)
{
    ob_start();
    imagejpeg($gdimage);
    return(ob_get_clean());
}
like image 5
andrea Avatar answered Oct 14 '22 23:10

andrea