-
Notifications
You must be signed in to change notification settings - Fork 3
Leverage server-side HEIC conversion when available #1074
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…tion Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
|
@copilot can we add an e2e test for this perhaps? |
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Added e2e test in commit a1e910f. The test covers both scenarios:
The test checks server capability via the |
|
Size Change: +275 B (0%) Total Size: 16.6 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces server-side HEIC conversion support when WordPress has HEIC capabilities (e.g., Imagick with libheif). The implementation detects server capabilities via REST API and intelligently chooses between server-side and client-side conversion paths while maintaining client-side thumbnail generation.
Key changes:
- Added server capability detection using
wp_image_editor_supports(['mime_type' => 'image/heic'])and exposed via REST API - Modified operation flow to upload HEIC files directly when server supports them, then fetch converted JPEG for client-side thumbnail generation
- Implemented graceful fallback to existing client-side conversion when server doesn't support HEIC
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| inc/functions.php | Adds server-side HEIC capability detection and exposes it through REST API index |
| packages/editor/src/types.ts | Adds supports_heic field to REST base record type definition |
| packages/editor/src/init/index.ts | Propagates supports_heic from REST API to upload store settings |
| packages/upload-media/src/store/types.ts | Adds optional supportsHeic field to Settings interface |
| packages/upload-media/src/store/private-actions.ts | Implements conditional logic for server-side HEIC conversion with dynamic operation insertion |
| tests/e2e/specs/images/heic-server-side.spec.ts | Adds comprehensive E2E tests for both server-supported and fallback scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Added isHeicFile() utility function to avoid code duplication - Fixed operation order for server-side HEIC conversion by adding FetchRemoteFile, GenerateMetadata, GenerateCaptions, and ThumbnailGeneration operations dynamically in uploadItem() after upload completes - This ensures operations execute in correct sequence: Upload → FetchRemoteFile → GenerateMetadata → GenerateCaptions → ThumbnailGeneration Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Leverage server-side HEIC conversion
This PR implements server-side HEIC conversion support as described in issue #483.
Summary
When a WordPress server supports HEIC image format (e.g., via Imagick with libheif), this feature allows uploading HEIC files directly to the server for conversion, rather than converting them client-side. This reduces client-side processing load while maintaining full control over thumbnail generation.
Changes Made
1. Server Capability Detection (PHP)
wp_image_editor_supports(['mime_type' => 'image/heic'])check ininc/functions.phpsupports_heicflag through REST API index endpoint (filter_rest_index)2. TypeScript Type Definitions
supports_heic: booleantoRestBaseRecordtype (packages/editor/src/types.ts)supportsHeic?: booleantoSettingsinterface (packages/upload-media/src/store/types.ts)siteDataFieldsarray to fetchsupports_heicfrom REST API (packages/editor/src/init/index.ts)supportsHeicto upload store settings3. Upload Configuration (
packages/upload-media/src/store/private-actions.ts)isHeicFile()utility function to check if a file is HEIC/HEIFaddItem(): Detect HEIC files and disable server-side thumbnail generation when server supports HEICgenerate_sub_sizes: falsefor HEIC files whensupportsHeicis true4. Operation Flow Restructuring (
packages/upload-media/src/store/private-actions.ts)In
prepareItem(): When server will convert HEIC, only add Upload operationIn
uploadItem(): After uploading HEIC to supporting serverFetchRemoteFile → GenerateMetadata → GenerateCaptions → ThumbnailGenerationitem.fileto the converted file so thumbnail generation works correctly5. E2E Tests (
tests/e2e/specs/images/heic-server-side.spec.ts)Operation Flow Comparison
Before (client-side conversion):
After (server-side when supported):
Fallback (server doesn't support HEIC):
Benefits
✅ Offloads HEIC conversion to server when available (reduces client-side processing)
✅ Maintains full control over client-side thumbnail generation
✅ Graceful fallback to client-side conversion when server doesn't support HEIC
✅ Works seamlessly with existing WordPress image editor infrastructure
✅ No user-facing changes required - works automatically based on server capabilities
✅ Proper operation sequencing ensures converted file is available for all subsequent operations
Testing Requirements
This feature requires testing with:
E2E test checklist:
Related Issues
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.