Infinite Possibilities
Infinite Possibilities

Reputation: 7466

PHP image width when the image is in a variable

I have loaded an image from database to a variable named $image.
How can I get the width of the image while it is stored in the variable?

The $image variable contains the data of the image. When I store the image, I just read it from the temp folder and write it to the database.


The accepted answer fulfills this question.
However, I am doing some resizing on the $im variable, so I need to reconvert it to string data, that can be done with the imagepng function.

Upvotes: 1

Views: 445

Answers (2)

toopay
toopay

Reputation: 1635

If you have GD installed, you can just use something like $size = getimagesize($filename);

Upvotes: -1

Yoshi
Yoshi

Reputation: 54649

You could use imagecreatefromstring with imagesx.

Like:

$im = imagecreatefromstring($image);
if ($im !== false) {
    echo imagesx($im);
}

Upvotes: 2

Related Questions