Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HEIC uploading + JPEG conversion #7034

Closed

Conversation

adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Jul 15, 2024

First pass, excluding tests

Trac ticket: https://core.trac.wordpress.org/ticket/53645


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented Jul 15, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein, noisysocks, swissspidy, spacedmonkey, peterwilsoncc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@noisysocks
Copy link
Member

Thanks for the PR @adamsilverstein. It doesn't seem to work when I test it, though.

If I drop a .heic into the gallery I see an error, the image cannot be previewed, and the file type is still image/heic.

Kapture.2024-07-16.at.11.44.18.mp4

@adamsilverstein adamsilverstein changed the title Add support for HEIC uploading Add support for HEIC uploading + JPEG conversion Jul 16, 2024
@noisysocks
Copy link
Member

Here's a fix for the Image block: WordPress/gutenberg#63643

@swissspidy
Copy link
Member

Interestingly, in my project I just saw some differences in the browser tests where the browser-determined mime type was once image/heic and once image/heif. Strangely that was for the same image 🤔

I don't know how the mime type detection works in PHP, but it might be worth testing this with a few different HEIC images to see if the image/heif mime type also needs to be checked (in addition to just image/heic).

HEIC images have a different FourCC code depending on the type:

'mif1', // .heic / image/heif
'msf1', // .heic / image/heif-sequence
'heic', // .heic / image/heic
'heix', // .heic / image/heic
'hevc', // .heic / image/heic-sequence
'hevx', // .heic / image/heic-sequence

adamsilverstein and others added 3 commits July 17, 2024 09:14
Co-authored-by: Robert Anderson <robert@noisysocks.com>
@adamsilverstein
Copy link
Member Author

Looks like media.php references IMAGETYPE_HEIF but combat.php defines IMAGETYPE_HEIC.
Ah, right. sticking with HEIC for now, fixed in a65c937

@adamsilverstein
Copy link
Member Author

Interestingly, in my project I just saw some differences in the browser tests where the browser-determined mime type was once image/heic and once image/heif. Strangely that was for the same image 🤔

I don't know how the mime type detection works in PHP, but it might be worth testing this with a few different HEIC images to see if the image/heif mime type also needs to be checked (in addition to just image/heic).

HEIC images have a different FourCC code depending on the type:

'mif1', // .heic / image/heif
'msf1', // .heic / image/heif-sequence
'heic', // .heic / image/heic
'heix', // .heic / image/heic
'hevc', // .heic / image/heic-sequence
'hevx', // .heic / image/heic-sequence

Currently I'm using this bit of code which I haven't really verified works beyond a single test image. This will be important to test throughly because PHP won't properly detect the mime type.

I plan to add tests next and can bundle several test images to make sure they are identified correctly (and hopefully that we can get the sizes correctly with Imagick). I'll be looking for test images that have a compatible license and are relatively small, contributions welcome!

@adamsilverstein
Copy link
Member Author

Here's a fix for the Image block: WordPress/gutenberg#63643

Amazing, thank you!

@spacedmonkey
Copy link
Member

This works well in my testing. I really like that you get to the original image from the attachment screen.

Screenshot 2024-07-17 at 22 38 48

@spacedmonkey
Copy link
Member

Worth noting that I tried uploading heif from https://filesampleshub.com/format/image/heif. I was unable to upload and I get this error message.
Screenshot 2024-07-17 at 22 48 03

@adamsilverstein
Copy link
Member Author

This works well in my testing. I really like that you get to the original image from the attachment screen.

Screenshot 2024-07-17 at 22 38 48

yum!

@adamsilverstein
Copy link
Member Author

Worth noting that I tried uploading heif from filesampleshub.com/format/image/heif. I was unable to upload and I get this error message. Screenshot 2024-07-17 at 22 48 03

Thanks for the link to the sample files, that is helpful.

I could try to extend full support to .heif files. Do we know how common these are or where/how they are created? I double checked and the files my iphone was creating before I switched it off were .heic files.

@noisysocks
Copy link
Member

As an experiment I took a .heic image from my iPhone and renamed it to .heif. Regardless of whether the file is .heic or .heif it works the same in Preview and other Apple apps. In both cases the MIME type that file -I spits out is image/heic.

$ file -I playground-1.HEIF
playground-1.HEIF: image/heic; charset=binary
$ file -I playground-2.HEIC
playground-2.HEIC: image/heic; charset=binary

I think it makes sense to have WordPress do the same. Support both .heic and .heif but map them to image/heic in both cases.

@noisysocks
Copy link
Member

Added some tests @adamsilverstein.

I think coverage is okay, though I struggled to write one for the changes to wp_generate_attachment_metadata. Ended up deciding it's not worth the effort since it more or less is already covered by test_resize_heic.

Something strange I noticed is that our PHP 8.3 container in GitHub Actions doesn't have the Imagick extension enabled but the other containers do 🤷‍♂️

@noisysocks
Copy link
Member

This still tests really well for me. Here's how things look now that WordPress/gutenberg#63643 is merged.

Kapture.2024-08-02.at.12.11.55.mp4

I'll commit on Monday if there's no objections. Keen to get something in early for 6.7 so that there's plenty of time for feedback and iteration.

@noisysocks
Copy link
Member

Committed in r58849.

@noisysocks noisysocks closed this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants