Skip to content

Unable to use getimagesize on HEIC/HEIF images #20863

Open

Description

@earthiverse

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

Activity

  1. iluuu1994 commented on Jan 8, 2026

    @iluuu1994
    Member
  2. benstonezhang commented on Jan 8, 2026

    @benstonezhang
    Contributor

    seems those photo were taken with samsung camera, is different with the photo from iphone.

  3. jordikroon commented on Jan 8, 2026

    @jordikroon
    Member

    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.

  4. earthiverse commented on Jan 8, 2026

    @earthiverse
    Author

    seems those photo were taken with samsung camera, is different with the photo from iphone.

    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

  5. benstonezhang commented on Jan 9, 2026

    @benstonezhang
    Contributor

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

  6. iluuu1994 commented on Jan 9, 2026

    @iluuu1994
    Member

    I don't work on this area of PHP, I'll leave this up to somebody else. Maybe @devnexen?

  7. Girgias commented on Jan 11, 2026

    @Girgias
    Member

    Also pinging @ndossche as I think they were involved in the AVIX code landing too.

  8. ndossche commented on Jan 11, 2026

    @ndossche
    Member

    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.

  9. iliaal commented on Jun 26, 2026

    @iliaal
    Member

    Fixed in dfac2da (PHP 8.5.0), which added HEIF/HEIC support to getimagesize(). Closing as resolved.

  10. earthiverse commented on Jun 26, 2026

    @earthiverse
    Author

    Fixed in dfac2da (PHP 8.5.0), which added HEIF/HEIC support to getimagesize(). Closing as resolved.

    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.

    PHP 8.5.7 (cli) (built: Jun  2 2026 20:59:56) (NTS)
    Copyright (c) The PHP Group
    Built by Shivam Mathur
    Zend Engine v4.5.7, Copyright (c) Zend Technologies
        with Xdebug v3.5.3, Copyright (c) 2002-2026, by Derick Rethans
        with Zend OPcache v8.5.7, Copyright (c), by Zend Technologies
    

    Can you please re-open this issue?

  11. reopened this on Jun 26, 2026
  12. iliaal commented on Jun 26, 2026

    @iliaal
    Member

    Can you provide sample images, plz, be interesting why they don't work

  13. benstonezhang commented on Jun 26, 2026

    @benstonezhang
    Contributor

    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.

  14. iliaal commented on Jun 26, 2026

    @iliaal
    Member

    Yeah, exif seems like it would be the way to go especially for getimagesize()

  15. self-assigned this
    on Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions