Get Image Info From Binary Data

Get Image Info From Binary Data

I have encountered a problem where my co-worker stored an image into database as binary data. For example, it contains value of “iVBORw0KGgoAAAANSUhEUgAAASwAAAD6…..” in the database. Now I want to get the width and height information about the image. What I normally do is to use getimagesize function. However, the getimagesize function only receieves parameter of the path to the image on the server’s directory, not from database. I did some research and found the following code can be used to get the width and height information from a binary image data.
$src = imagecreatefromstring($binary_image_data);
$width = imagesx($src);
$height = imagesy($src);
It is quite simple, but if you don’t know it, you will never be able to figure it out. I hope this bit of code can help someone.

Leave a Reply

Your email address will not be published.

My new Snowflake Blog is now live. I will not be updating this blog anymore but will continue with new contents in the Snowflake world!