5

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...

2 Answers 2

9

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

1 Comment

change ob_end_flush() to ob_end_clean() if you don't want the buffer echo'd
5
function image_data($gdimage)
{
    ob_start();
    imagejpeg($gdimage);
    return(ob_get_clean());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.