php-imagine / Imagine

PHP Object Oriented image manipulation library
https://imagine.readthedocs.io
Other
4.42k stars 530 forks source link

ExifMetadataReader::readFile() does not return Exif data #728

Closed stevekr closed 4 years ago

stevekr commented 4 years ago

Issue description

No Exif data returned when using (new ExifMetadataReader())->readFile($path) while exif_read_data($path, null, true, false) works fine.

What version of Imagine are you using?

1.2.2

What's the PHP version you are using?

7.3.11

What's the imaging library you are using [gd/imagick/gmagick/any]?

any

What's the imaging library configuration

--

Minimal PHP code to reproduce the error:

(new ExifMetadataReader())->readFile($path)
mlocati commented 4 years ago

I did this test:

  1. download https://github.com/ianare/exif-samples/blob/master/tiff/Arbitro.tiff and https://github.com/ianare/exif-samples/blob/master/jpg/Canon_40D.jpg
  2. Execute this code:
    print_r((new ExifMetadataReader())->readFile('./Arbitro.tiff'));
    print_r((new ExifMetadataReader())->readFile('./Canon_40D.jpg'));

The output is:

Imagine\Image\Metadata\MetadataBag Object
(
    [data:Imagine\Image\Metadata\MetadataBag:private] => Array
        (
            [uri] => ./Arbitro.tiff
            [filepath] => /absolute/path/to/Arbitro.tiff
            [file.FileDateTime] => 0
            [file.FileSize] => 6925
            [file.FileType] => 8
            [file.MimeType] => image/tiff
            [file.SectionsFound] => ANY_TAG, IFD0
            [computed.html] => width="174" height="38"
            [computed.Height] => 38
            [computed.Width] => 174
            [computed.IsColor] => 1
            [computed.ByteOrderMotorola] => 1
            [ifd0.ImageWidth] => 174
            [ifd0.ImageLength] => 38
            [ifd0.BitsPerSample] => Array
                (
                    [0] => 8
                    [1] => 8
                    [2] => 8
                    [3] => 8
                )

            [ifd0.Compression] => 5
            [ifd0.PhotometricInterpretation] => 2
            [ifd0.StripOffsets] => 8
            [ifd0.Orientation] => 1
            [ifd0.SamplesPerPixel] => 4
            [ifd0.RowsPerStrip] => 38
            [ifd0.StripByteCounts] => 6391
            [ifd0.PlanarConfiguration] => 1
            [ifd0.Predictor] => 2
            [ifd0.ExtraSample] => 1
            [ifd0.SampleFormat] => Array
                (
                    [0] => 1
                    [1] => 1
                    [2] => 1
                    [3] => 1
                )

            [ifd0.ExtensibleMetadataPlatform] => <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.1.2">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:tiff="http://ns.adobe.com/tiff/1.0/">
         <tiff:Compression>5</tiff:Compression>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>

        )

)
Imagine\Image\Metadata\MetadataBag Object
(
    [data:Imagine\Image\Metadata\MetadataBag:private] => Array
        (
            [uri] => ./Canon_40D.jpg
            [filepath] => /absolute/path/to/Canon_40D.jpg
            [file.FileDateTime] => 0
            [file.FileSize] => 7958
            [file.FileType] => 2
            [file.MimeType] => image/jpeg
            [file.SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS, INTEROP
            [computed.html] => width="100" height="68"
            [computed.Height] => 68
            [computed.Width] => 100
            [computed.IsColor] => 1
            [computed.ByteOrderMotorola] => 0
            [computed.CCDWidth] => 0mm
            [computed.ApertureFNumber] => f/7.1
            [computed.UserComment] =>
            [computed.UserCommentEncoding] => UNDEFINED
            [computed.Thumbnail.FileType] => 2
            [computed.Thumbnail.MimeType] => image/jpeg
            [ifd0.Make] => Canon
            [ifd0.Model] => Canon EOS 40D
            [ifd0.Orientation] => 1
            [ifd0.XResolution] => 72/1
            [ifd0.YResolution] => 72/1
            [ifd0.ResolutionUnit] => 2
            [ifd0.Software] => GIMP 2.4.5
            [ifd0.DateTime] => 2008:07:31 10:38:11
            [ifd0.YCbCrPositioning] => 2
            [ifd0.Exif_IFD_Pointer] => 214
            [ifd0.GPS_IFD_Pointer] => 978
            [thumbnail.Compression] => 6
            [thumbnail.XResolution] => 72/1
            [thumbnail.YResolution] => 72/1
            [thumbnail.ResolutionUnit] => 2
            [thumbnail.JPEGInterchangeFormat] => 1090
            [thumbnail.JPEGInterchangeFormatLength] => 1378
            [exif.ExposureTime] => 1/160
            [exif.FNumber] => 71/10
            [exif.ExposureProgram] => 1
            [exif.ISOSpeedRatings] => 100
            [exif.ExifVersion] => 0221
            [exif.DateTimeOriginal] => 2008:05:30 15:56:01
            [exif.DateTimeDigitized] => 2008:05:30 15:56:01
            [exif.ComponentsConfiguration] => 
            [exif.ShutterSpeedValue] => 483328/65536
            [exif.ApertureValue] => 368640/65536
            [exif.ExposureBiasValue] => 0/1
            [exif.MeteringMode] => 5
            [exif.Flash] => 9
            [exif.FocalLength] => 135/1
            [exif.UserComment] =>
            [exif.SubSecTime] => 00
            [exif.SubSecTimeOriginal] => 00
            [exif.SubSecTimeDigitized] => 00
            [exif.FlashPixVersion] => 0100
            [exif.ColorSpace] => 1
            [exif.ExifImageWidth] => 100
            [exif.ExifImageLength] => 68
            [exif.InteroperabilityOffset] => 948
            [exif.FocalPlaneXResolution] => 3888000/876
            [exif.FocalPlaneYResolution] => 2592000/583
            [exif.FocalPlaneResolutionUnit] => 2
            [exif.CustomRendered] => 0
            [exif.ExposureMode] => 1
            [exif.WhiteBalance] => 0
            [exif.SceneCaptureType] => 0
            [gps.GPSVersion] => 
            [interop.InterOperabilityIndex] => R98
            [interop.InterOperabilityVersion] => 0100
        )

)

So it seems to me that everything is working as expected...

What do you get if you run the following code? var_dump((new ExifMetadataReader())->readFile($path));

stevekr commented 4 years ago

What do you get if you run the following code? var_dump((new ExifMetadataReader())->readFile($path));

I get:

object(Imagine\Image\Metadata\MetadataBag)#6 (1) {
  ["data":"Imagine\Image\Metadata\MetadataBag":private]=>
  array(2) {
    ["uri"]=>
    string(75) "/path/to/image.jpg"
    ["filepath"]=>
    string(75) "/path/to/image.jpg"
  }
}
mlocati commented 4 years ago

Could you post here your image?

ausi commented 4 years ago

You can also try the following line, this is similar to how Imagine reads the EXIF data:

var_dump(exif_read_data('data://image/jpeg;base64,'.base64_encode(file_get_contents($path)), null, true, false));
stevekr commented 4 years ago

This gives me fatal error Uncaught TypeError: exif_read_data() expects parameter 2 to be string, null given.

Update: If I remove declare(strict_types=1); then I get Warning: exif_read_data(): Unable to open file

ausi commented 4 years ago

What do you get when you run var_dump(implode(',', stream_get_wrappers()));?

stevekr commented 4 years ago

string(61) "https,ftps,compress.zlib,php,file,glob,data,http,ftp,zip,phar"

ausi commented 4 years ago

What do you get with the following line?

var_dump(exif_read_data('data://image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAABAAEDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD9/KKKKAP/2Q==', null, true, false));
stevekr commented 4 years ago

Still Warning: exif_read_data(): Unable to open file

ausi commented 4 years ago

Looks like your installation doesn’t support data URIs even though the data stream wrapper is enabled.

You can verify my assumption by running this: var_dump(file_get_contents('data://text/plain,test'));

stevekr commented 4 years ago

Warning: file_get_contents(): data:// wrapper is disabled in the server configuration by allow_url_fopen=0

ausi commented 4 years ago

If you set allow_url_fopen=1 in your php.ini the issue should get fixed.

stevekr commented 4 years ago

Thanks for helping me debug this. If there is no way to make it work without url fopen enabled, maybe it should be somewhere in the ExifMetadataReader source that it requires allow_url_fopen=1.

mlocati commented 4 years ago

maybe it should be somewhere in the ExifMetadataReader source that it requires allow_url_fopen=1

@stevekr I'm not sure what you mean with this. Could you explain it in other words?

stevekr commented 4 years ago

For example put it in ExifMetadataReader::extract() or class docblock just for a reminder to others who may have similar problem like I did.

mlocati commented 4 years ago

What about something like #729 ?

stevekr commented 4 years ago

Even better :)

ausi commented 4 years ago

I looked up the PHP documentation for data:// and it says “Restricted by allow_url_fopen: No”: https://www.php.net/manual/en/wrappers.data.php

We should probably check if the documentation is wrong or if there is something else at the root of this issue.

mlocati commented 4 years ago

I tried to set allow_url_fopen=1 in my php.ini file (php 7.3.12) and that prevented var_dump(file_get_contents('data://text/plain,test')); from working, so yes, imho there's something wrong, either in the documentation or in the php code (and of course I think that PHP should behave like described in the manual). Are you willing to submit a bug to https://bugs.php.net ?

ausi commented 4 years ago

Are you willing to submit a bug to bugs.php.net ?

Yes, I will. But it will take some time 🙃

mlocati commented 4 years ago

I can do that, if you prefer

ausi commented 4 years ago

That would be great, thanks!

mlocati commented 4 years ago

There's already a bug report: https://bugs.php.net/bug.php?id=47336

I added this comment: https://bugs.php.net/bug.php?id=47336#1575618618