Make WordPress Core

Opened 10 years ago

Last modified 7 years ago

#29795 new enhancement

Set JPEG quality for individual image_size

Reported by: drivingralle's profile Drivingralle Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Media Keywords: needs-patch dev-feedback
Focuses: Cc:

Description

Based on this idea I would like to work on this topic:
https://wordpress.org/ideas/topic/jpeg-compression-factor-for-different-image_size

Usecase:
If a theme use an image as a full screen background image the image quality doesn't need to be as high as for a featured image or thumbnail.
The difference in file-size would benefit the webspace and the speed on page load.

I can think of two ways to solve it:

  1. Add a argument to add_image_size:
    add_image_size( $name, $width, $height, $crop, $quality ); 
    
  1. Add filter for it:
    apply_filters( 'jpeg_quality_for_image_size', $quality, $size );
    

In both cases the information about the current image size needs to be added to the set_quality or get_quality functions to be available.

Attachments (1)

29795.patch (1.0 KB) - added by Drivingralle 9 years ago.
I have tried to write a patch to add a filter for the image quality see the patch file. In collaboration with @hinnerk and @luminuu.

Download all attachments as: .zip

Change History (8)

#1 @markoheijnen
10 years ago

This is something I'm working on in https://github.com/markoheijnen/Improved-image-editor.
My idea is to have an extra argument to add_image_size which allows all kinds of arguments including quality.

#2 @kirasong
10 years ago

I think this is a good feature suggestion, but would need parameters passed to all places we currently save images to be able to add the filter. If we can handle it in the way Marko is describing, that would definitely be ideal.

Last edited 10 years ago by kirasong (previous) (diff)

#3 @kirasong
10 years ago

Marko has reminded me that we have access to the name of the size during multi_resize, so we might be able to do this more simply than I expected.

#4 @chriscct7
9 years ago

  • Keywords needs-patch added

Want to take this on @DH-Shredder?

#5 @markoheijnen
9 years ago

I'm still wondering if this should be in core or not. I do believe it's a benefit to lower the quality for a smaller image. I would still go for using the filter instead of another argument. So maybe we don't need to implement this directly in core but at least give the option to make this easier. I still think extending an image editor is always needed which is a shame.

Codewise, Checkout the updates I did on https://github.com/markoheijnen/Improved-image-editor. Basically it's adding a function like register_image_size_info(). So instead of adding another argument to add_image_size, there is a more general way to describe an image size. Having an $arg parameter to add_image_size() could still work though.

@Drivingralle
9 years ago

I have tried to write a patch to add a filter for the image quality see the patch file. In collaboration with @hinnerk and @luminuu.

#6 @Drivingralle
9 years ago

  • Keywords dev-feedback added

#7 @leec87
7 years ago

I'd say this would be a very welcomed feature, doesn't look too complicated, and in response to Mark, should definitely be in the core as another argument.

I have large, full-width custom image sizes used for page headers.. but are being used by a data- attribute, leaving the src free to be able to use a low-quality version in future.

This would then be ideal, to initially load the low filesize version, and then the usual when it loads.

Please implement! :)

Last edited 7 years ago by leec87 (previous) (diff)
Note: See TracTickets for help on using tickets.