13

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.

rymo
  • 3,285
  • 2
  • 36
  • 40

2 Answers2

26

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.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • 9
    wow, that did the trick! thanks so much! here's what I used: `exif_read_data("data://image/jpeg;base64," . base64_encode($imageString))` – rymo Mar 28 '11 at 22:35
8

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'];
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
brismuth
  • 36,149
  • 3
  • 34
  • 37