Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract EXIF data from an image blob (binary string) in PHP

The PHP function exif_read_data() requires a filename for input, however I only have the image data in a string (such that I can use imagecreatefromstring()) and I can not write it to a temp file. How do I extract EXIF information without writing this image string to disk? All I really want is the Orientation attribute. This is on a Linux system if it matters.

like image 935
rymo Avatar asked Mar 28 '11 22:03

rymo


2 Answers

Adding @rymo’s comment on @MarcB’s answer as a separate answer:

This works:

$exif = exif_read_data("data://image/jpeg;base64," . base64_encode($image));
echo $exif['Orientation'];
like image 86
brismuth Avatar answered Oct 10 '22 21:10

brismuth


A stream wrapper can turn your string/image into something useable as a filehandle, as shown here. However, I can't see any way of turning that filehandle into something that can masquerade as the filename that exif_read_data expects.

You might try passing the data:// pseudo-url listed on that page and see if the exif function will accept it.

like image 36
Marc B Avatar answered Oct 10 '22 19:10

Marc B