Get image size from handler

2019-02-14 03:17发布

问题:

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

回答1:

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.



回答2:

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