Skip to content

Auto convert HEIC images to JPEG on upload#7035

Closed
noisysocks wants to merge 1 commit into
WordPress:trunkfrom
noisysocks:add/auto-convert-heic-images
Closed

Auto convert HEIC images to JPEG on upload#7035
noisysocks wants to merge 1 commit into
WordPress:trunkfrom
noisysocks:add/auto-convert-heic-images

Conversation

@noisysocks

@noisysocks noisysocks commented Jul 16, 2024

Copy link
Copy Markdown
Member

Automatically converts HEIC images to JPEG on upload. See ticket for details and motivation.

Implementation is based on the GPL2 HEIC Support plugin written by @csalzano. Attribution is included in the doc comment.

Unlike the HEIC Support plugin, HEIC images are always converted to JPEG and the original file is deleted. This is what the majority of users will want and aligns with what Apple does in its apps that support HEIC. Website admins can customise the behaviour by installing a plugin (e.g. HEIC Support) or by removing the hook:

remove_filter( 'wp_handle_upload_prefilter', 'wp_auto_convert_heic_images' );

The existing error message that appears when you upload a HEIC image that encourages the user to convert the image and try again is suppressed when auto-conversion is enabled.

Here's a video showing how this looks:

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

You'll note in the video that the Image block doesn't look great while the HEIC is uploading. This is because I'm using a browser that doesn't support HEIC and so the Image block isn't able to show a preview. We'll need to improve this in Gutenberg as a separate PR by e.g. showing a nicer placeholder when there is no image available.

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

@github-actions

github-actions Bot commented Jul 16, 2024

Copy link
Copy Markdown

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 noisysocks, azaozz.

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

@github-actions

Copy link
Copy Markdown

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.

@azaozz

azaozz commented Jul 17, 2024

Copy link
Copy Markdown
Contributor

Code looks good imho. Wondering if it may be good to inform the user that an image they uploaded was converted? Or perhaps treat the conversions as "standard behavior" and inform them when it fails? Perhaps in the second case WP can advise them to convert it to JPEG and upload it again?

Also, by default WP attempts to keep uploaded images as-is and treat them as "backups". Wondering if this behavior should continue when converting .heic/.heif images too?

@noisysocks

Copy link
Copy Markdown
Member Author

Also, by default WP attempts to keep uploaded images as-is and treat them as "backups". Wondering if this behavior should continue when converting .heic/.heif images too?

Yeah this is what the alternative solution #7034 does. I prefer it. Will close this PR.

@noisysocks noisysocks closed this Jul 18, 2024
@noisysocks noisysocks deleted the add/auto-convert-heic-images branch July 18, 2024 01:12
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.

2 participants