Search code examples
phpimage-manipulationexif

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.


Solution

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