Extract Image Dimensions from Base64 String

2020-04-02 13:03发布

问题:

Is there a relatively simple way (perhaps regular expressions?) of detecting the dimensions -height & width - of an image from a base64 string (and perhaps the filesize)? That is to say without actually creating an image resource?

回答1:

Decode the base64, and use getimagesizefromstring().

http://www.php.net/manual/en/function.getimagesizefromstring.php

This will be way more reliable than trying to write your own handling of each image type available.