JamesHeinrich / getID3

http://www.getid3.org/
Other
1.15k stars 245 forks source link

Use of undefined constant IMG_JPG - assumed 'IMG_JPG' (this will throw an Error in a future version of PHP) #293

Closed theonelucas closed 3 years ago

theonelucas commented 3 years ago

While trying to parse any jpg file, the following error occurs:

Use of undefined constant IMG_JPG - assumed 'IMG_JPG' (this will throw an Error in a future version of PHP)

Full $info object:

array:12 [
  "GETID3_VERSION" => "1.9.20-202012091120"
  "filesize" => 66705
  "filepath" => "/var/www/storage/app/photos/trash"
  "filename" => "07641ed6-9f25-498a-9793-c4d86dbcf528.jpg"
  "filenamepath" => "/var/www/storage/app/photos/trash/07641ed6-9f25-498a-9793-c4d86dbcf528.jpg"
  "avdataoffset" => 0
  "avdataend" => 66705
  "fileformat" => "jpg"
  "video" => array:4 [
    "dataformat" => "jpg"
    "lossless" => false
    "bits_per_sample" => 24
    "pixel_aspect_ratio" => 1.0
  ]
  "encoding" => "UTF-8"
  "mime_type" => "image/jpeg"
  "error" => array:1 [
    0 => "Caught exception: Use of undefined constant IMG_JPG - assumed 'IMG_JPG' (this will throw an Error in a future version of PHP)"
  ]
]

I'm currently using version 2.0.x-dev.

I noticed this problem was apparently fixed almost 10 years ago by this commit, but still it happened with me.

StudioMaX commented 3 years ago

Do you have gd extension installed?

JamesHeinrich commented 3 years ago

"GETID3_VERSION" => "1.9.20-202012091120" I'm currently using version 2.0.x-dev.

Would it not make sense for the 2.0.x-dev branch to use 2.0.x version numbering to reduce confusion?

StudioMaX commented 3 years ago

Seems this bug is from very old days. According to the documentation of getimagesize:

Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image.

There even someone left a comment 16 years ago:

Note that, if you're going to be a good programmer and use named constatnts (IMAGETYPE_JPEG) rather than their values (2), you want to use the IMAGETYPE variants - IMAGETYPE_JPEG, IMAGETYPE GIF, IMAGETYPE_PNG, etc. For some reason, somebody made a horrible decision, and IMG_PNG is actually 4 in my version of PHP, while IMAGETYPE_PNG is 3. It took me a while to figure out why comparing the type against IMG_PNG was failing...

This works in version 1.x as a workaround was added for this IMG_JPG variable https://github.com/JamesHeinrich/getID3/blob/80c557835768de3bb76e45878c18774ad522aafc/getid3/getid3.php#L21-L23 but in version 2.x this workaround was apparently removed. Probably we need to use IMAGETYPE_JPEG instead, because it works on all versions.

theonelucas commented 3 years ago

Do you have gd extension installed?

That indeed solved the problem. I read the requirement for the exif lib but did not see any mentions to GD, even though I could've assumed it would be required.

StudioMaX commented 3 years ago

Would it not make sense for the 2.0.x-dev branch to use 2.0.x version numbering to reduce confusion?

I thought about this, but since version 2.x is in development status it doesn't have a specific version. I hope that someday we will switch to it as the main branch, since support for PHP 5.3 in GetID3 1.x in 2021 is rather doubtful.