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?
To decode with base64 you need to use the --decode flag. With encoded string, you can pipe an echo command into base64 as you did to encode it. Using the example encoding shown above, let's decode it back into its original form. Provided your encoding was not corrupted the output should be your original string.
Each Base64 digit represents exactly 6 bits of data. So, three 8-bits bytes of the input string/binary file (3×8 bits = 24 bits) can be represented by four 6-bit Base64 digits (4×6 = 24 bits). This means that the Base64 version of a string or file will be at least 133% the size of its source (a ~33% increase).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With