Convert images to optimized formats#50
Merged
Merged
Conversation
…task/format-conversion
…task/format-conversion
…task/format-conversion
- Add support for output format selection (smallest, webp, avif) - Remove force: true from checkbox interactions for more reliable tests - Improve setConversionSettings function to handle different conversion formats - Add switch statement to handle output format radio button selection
- Add output: 'smallest' parameter to setConversionSettings call - Ensures test uses the smallest file format conversion option - Improves test clarity by being explicit about conversion settings
- Fix bulk optimization logic to include already compressed images that need conversion - Update available-for-optimization array to consider both compression and conversion needs - Enhance bulk optimization JavaScript to properly display compression and conversion results - Add comprehensive test for conversion-only optimization scenario This ensures that when conversion is enabled, bulk optimization will process: 1. Uncompressed images (compression + conversion) 2. Already compressed images that need conversion (conversion only) Previously, already compressed images were excluded from bulk optimization even when they needed conversion, causing incomplete optimization runs.
…ompression - Change 'activated for compression' to 'activated for optimization' - Change 'is compressed' to 'is optimized' in size count messages - Better reflects that bulk optimization now handles both compression and conversion - Improves user understanding of the feature scope
- Fix available-for-optimization condition to check both uncompressed and unconverted sizes - Separate uncompressed and unconverted size filtering when conversion is enabled - Ensure compressed images can still be converted when conversion feature is toggled on - Update test to properly verify optimization statistics with conversion scenarios - Add test coverage for compressed images being eligible for conversion This resolves issues where already compressed images weren't being converted when users enabled the conversion feature after initial compression.
…task/format-conversion
Rename 'usage' parameter to 'compressions_used' in estimate_cost method to better reflect its purpose and improve code readability.
- Move Tiny_Picture initialization to init() method for better lifecycle management - Extract get_estimated_bulk_cost() method from render_bulk_optimization_page() to improve code organization and testability - Add comprehensive unit tests for bulk cost estimation scenarios: - Basic cost calculation without conversion - Cost calculation with format conversion enabled - Improve code readability and maintainability
- Add tests for plugin initialization and configuration - Improve test structure and assertions - Expand test cases to cover more functionality
- Add estimated_credit_use statistic to track compression credits needed - Update cost calculation to use accurate credit estimates instead of simple multiplication - Handle conversion scenarios properly: * Uncompressed images needing compression + conversion = 2 credits each * Compressed images needing only conversion = 1 credit each - Fix null handling for tiny_meta_value in bulk optimization statistics - Update tests to reflect accurate credit calculations and expectations This change provides more precise cost estimates for bulk optimization by tracking actual credit usage based on image compression and conversion states.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With file conversion enabled customers can choose to generate an additional image in a modern format. WebP and AVIF are known to produce a better quality and performance image. Unfortunately, not all browsers support it 100% so therefor we choose to supply it as an addition instead of replacing the image.
Changes
template_redirect(https://developer.wordpress.org/reference/hooks/template_redirect/). This will parse the page and read all images from the page. For each image, it will check if the disk contains a WebP or AVIF on the same location. If any, it will create a picture element and add the WebP/AVIF sources as a source attribute.class-tiny-compress.php:195. This would cause warnings in the customers' UI. This went unnoticed because we previously uploaded files and didn't need the ID of the recently uploaded file.Screenshots
The settings screen will show the options for conversion.
The media library list view ill show compression and conversions. Conversions are hidden if the conversion setting is disabled
Show image statistics for conversion..
Image statistics when conversion is disabled.
The image source is replaced by a picture element with the sources as attribute
Further Improvements
Below are further improvements we can make on this feature. Discussion is open to see if these are all could haves or if some of them are must haves.