Get image size from handler

2019-02-14 03:04发布

I'm creating an image editor in JS/PHP, but now I'm having trouble. First of all, I load the image from the database (load a blob with imagecreatefromstring). Then I apply a list of actions to this image. But how can I get the image size from this image handler I have then? Without writing it to a file or use a stream object. How??

2条回答
我命由我不由天
2楼-- · 2019-02-14 03:16

I doubt you can since php gd image object is a generic object, without considerations on the compression that will be used for storage (png/jpg/bmp ...)

查看更多
看我几分像从前
3楼-- · 2019-02-14 03:27

In case you mean the image dimensions:

$width  = imagesx($imgHandle);
$height = imagesy($imgHandle);

See imagesx() and imagesy().

If you mean filesize, that's not possible without converting the GD resource to some image format (GIF, PNG, JPEG) because the format determines the image size in bytes.

查看更多
登录 后发表回答