开发者

PHP image width when the image is in a variable

开发者 https://www.devze.com 2023-03-23 10:19 出处:网络
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?

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 th开发者_高级运维e 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.


You could use imagecreatefromstring with imagesx.

Like:

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消