Opened 3 years ago
Last modified 3 years ago
#12120 new enhancement
Force Media Image Generation (for thumbnails)
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Media | Version: | |
| Severity: | normal | Keywords: | has-patch needs-testing |
| Cc: |
Description
It would be very useful to force the generation of a thumbnail images for uploaded files. With content being syndicated to feeds, e-readers, and mobile devices, the ability to have a working thumbnail is more important.
For example, if the original image has dimensions of 250x50, and the default thumbnail size in WP is 150x150, a thumbnail will not be generated because the 50 height is smaller than the 150 pixel minimum.
The fix would be to include an additional parameter to the image_resize_dimensions to allow the function the dimensions. A filter could be applied to allow the user to set which images should force the generation of a resized image (i.e. to exclude a medium and large image from being generated for a 250x50 image) by passing in the original width/height and max width/height.
in wp-includes/media.php
========
function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
...
$force = apply_filters('image_resize_dimensions_force', $orig_w, $orig_h, $max_w, $max_h);
$dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop, $force);
========
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false, $force = false) {
...
if the resulting image would be the same size or larger we don't want to resize it
if ( $new_w >= $orig_w && $new_h >= $orig_h && !$force )
return false;
Attachments (1)
Change History (3)
- Keywords has-patch needs-testing added; media thumbnail removed
- Version 2.9.1 deleted
Ah yes, I should also mention my reason for doing this: PHP handles CMYK JPEG files just fine, whereas Internet Explorer does not. My client kept uploading CMYK JPEGs, not knowing the difference between that and an RGB JPEG.
The bad solution was to tell him to stop uploading CMYK JPEGs. The good solution was to write this patch, set force_image_resize to true, use the "large" thumbnail, and tell him "problem solved!" PHP generates an RGB JPEG from his CMYK JPEG, Internet Explorer displays it successfully, and all is right in the world.

I wrote a patch to do this. It adds a force_image_resize filter, which receives the name of the image size ('thumbnail', 'medium', etc.) so that they can be selectively forced to resize.