Repository navigation
Unable to use getimagesize on HEIC/HEIF images #20863
Copy link
Copy link
Open
Description
Description
I downloaded the heic from the pull request #18940, and that one does work, but none of the sample images I downloaded from https://heic.digital/samples/ work.
The following code:
<?php
$dir = __DIR__;
$allowedExt = ['jpg', 'jpeg', 'heic', 'heif'];
foreach (new DirectoryIterator($dir) as $file) {
if ($file->isDot() || !$file->isFile()) {
continue;
}
$ext = strtolower($file->getExtension());
if (!in_array($ext, $allowedExt, true)) {
continue;
}
$path = $file->getPathname();
$info = getimagesize($path);
if ($info === false) {
echo "Failed: $path\n";
continue;
}
[$width, $height] = $info;
echo "$path => {$width}x$height\n";
}Resulted in this output:
Failed: /Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/soundboard.heic
Failed: /Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/shelf-christmas-decoration.heic
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/test4pix.heic => 54x84
Failed: /Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/sewing-threads.heic
Failed: /Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/chef-with-trumpet.heic
Failed: /Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/childrens-show-theater.heic
Failed: /Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/classic-car.heic
Failed: /Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/greyhounds-looking-for-a-table.heic
But I expected this output instead:
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/soundboard.heic => 4000x3000
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/shelf-christmas-decoration.heic => 4000x3000
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/test4pix.heic => 54x84
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/sewing-threads.heic => 4000x3000
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/chef-with-trumpet.heic => 4032x3024
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/converted.jpeg => 8736x5856
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/childrens-show-theater.heic => 4032x3024
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/classic-car.heic => 3024x4032
/Users/earthiverse/Sites/media-store/tests/Codeception/Support/Data/images/heif/greyhounds-looking-for-a-table.heic => 3024x4032
PHP Version
PHP 8.5.1 (cli) (built: Dec 16 2025 15:59:07) (NTS)
Copyright (c) The PHP Group
Built by Shivam Mathur
Zend Engine v4.5.1, Copyright (c) Zend Technologies
with Xdebug v3.5.0, Copyright (c) 2002-2025, by Derick Rethans
with Zend OPcache v8.5.1, Copyright (c), by Zend Technologies
Operating System
MacOS Tahoe 26.2
Reacted by lubosdz and adrianlondon
Activity
iluuu1994 commentedon Jan 8, 2026
/cc @bukka @benstonezhang
benstonezhang commentedon Jan 8, 2026
seems those photo were taken with samsung camera, is different with the photo from iphone.
jordikroon commentedon Jan 8, 2026
It also applies to pictures made by Apple devices like an iPhone. I tried to test this with an image transferred from my phone and get the same results. The pictures in the image test folders though do seem to work.
earthiverse commentedon Jan 8, 2026
The website says (can't verify, but have no reason not to believe them) that 2 are from the iPad Air Gen 5, and 2 are from the iPhone 12 Pro.
I also tried the images from https://github.com/tigranbs/test-heic-images/tree/master after googling and finding AcademySoftwareFoundation/OpenImageIO#2794
image4.heic from there does work with getimagesize, but the other 3 do not.
tigranbs/test-heic-images#1 implies that image4.heic might be the only one with metadata
benstonezhang commentedon Jan 9, 2026
@iluuu1994
I had checked the code, in fact, the error happen in ext/standard/libavifinfo/avifinfo.c.
Some heic image didn't have field 'iprp' in meta box, so libavifinfo can not find field "ispe" which is used to parse image width and height.
Suggest to involve owner of libavifinfo to fix.
iluuu1994 commentedon Jan 9, 2026
I don't work on this area of PHP, I'll leave this up to somebody else. Maybe @devnexen?
Girgias commentedon Jan 11, 2026
Also pinging @ndossche as I think they were involved in the AVIX code landing too.
ndossche commentedon Jan 11, 2026
More so involved in fixing the buffer overflows, but yeah this may need adjustment in libavifinfo. Or perhaps there's a reason it does it that way, I don't know off the top of my head.
iliaal commentedon Jun 26, 2026
Fixed in dfac2da (PHP 8.5.0), which added HEIF/HEIC support to getimagesize(). Closing as resolved.
earthiverse commentedon Jun 26, 2026
I referenced the pull request this commit is a part of in the initial message (the first sentence), saying that the sample provided did work.
However, none of the heic images I encountered in the wild worked.
I also specified the version I tested with in my initial post (8.5.1), which is after 8.5.0.
Just re-tested, and it is still broken.
Can you please re-open this issue?
iliaal commentedon Jun 26, 2026
Can you provide sample images, plz, be interesting why they don't work
benstonezhang commentedon Jun 26, 2026
Cause these images didn't have field 'iprp' in meta box, which is the place to hold image size information defined in ISO standard, it's impossible to retrieve image size by libavif itself.
One potential workaround is to retrieve this information from exif.
iliaal commentedon Jun 26, 2026
Yeah, exif seems like it would be the way to go especially for getimagesize()