Skip to content

Convert images to optimized formats #50

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

Open
wants to merge 101 commits into
base: master
Choose a base branch
from

Conversation

tijmenbruggeman
Copy link
Collaborator

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.

  • We will convert using Tinify API/SDK after the image has been compressed.
  • The converted image is set in a picture element when it exists.

Screenshots

image
Conversion is (for now) enabled by default. It will cost one additional compression per image.

image
We show the optimized file and the size in the details tab.

Further Improvements

Below are options/features that can be added to this feature. Discussion is open to see if these are all could haves or if some of them are must haves.

  • Provide statistics for amount of converted images
    • Images generated
    • Images to be generated
  • Generate optimized format if already compressed
  • Bulk generate optimized formats for all ungenerated images
  • Add htaccess rules in addition to picture elements
  • Generate webp/avif for theme provided images.
  • Add option to replace original image
  • CDN/WP Offload support

@tijmenbruggeman tijmenbruggeman self-assigned this Apr 17, 2025
@rkoopmans rkoopmans requested a review from Copilot April 23, 2025 06:04
Copy link

@Copilot Copilot AI left a 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 the feature to convert images to optimized formats (WebP/AVIF) by integrating Tinify API functionality and updating the integration tests accordingly.

  • Added conversion settings tests to settings.spec.ts.
  • Introduced a new conversion.spec.ts to verify conversion behavior and display.
  • Updated bulkoptimization.spec.ts to incorporate conversion settings.

Reviewed Changes

Copilot reviewed 17 out of 34 changed files in this pull request and generated 2 comments.

File Description
test/integration/settings.spec.ts Added tests for conversion settings in the image optimization workflow.
test/integration/conversion.spec.ts New tests to verify image conversion functionality and display.
test/integration/bulkoptimization.spec.ts Adjusted imports to include conversion settings for bulk optimizations.
Files not reviewed (17)
  • .vscode/launch.json: Language not supported
  • src/class-tiny-compress-client.php: Language not supported
  • src/class-tiny-compress-fopen.php: Language not supported
  • src/class-tiny-compress.php: Language not supported
  • src/class-tiny-helpers.php: Language not supported
  • src/class-tiny-image-size.php: Language not supported
  • src/class-tiny-image.php: Language not supported
  • src/class-tiny-picture.php: Language not supported
  • src/class-tiny-plugin.php: Language not supported
  • src/class-tiny-settings.php: Language not supported
  • src/config/class-tiny-config.php: Language not supported
  • src/css/admin.css: Language not supported
  • src/views/compress-details.php: Language not supported
  • src/views/settings.php: Language not supported
  • test/helpers/mock-http-stream-wrapper.php: Language not supported
  • test/helpers/mock-tinify-client.php: Language not supported
  • test/helpers/wordpress.php: Language not supported

$stats['optimized-image-sizes'] += $image_stats['image_sizes_optimized'];
$stats['optimized-library-size'] += $image_stats['optimized_total_size'];
if ( $conversion_enabled ) {
$stats['available-unoptimised-sizes'] +=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it sucks to change it later, stick with one spelling (optimized)

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