#12120 closed feature request (wontfix)
Thumbnail image isn't created if the original is too small
Reported by: | atow | Owned by: | |
---|---|---|---|
Milestone: | Priority: | low | |
Severity: | normal | Version: | |
Component: | Media | Keywords: | close |
Focuses: | Cc: |
Description (last modified by )
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 (2)
Change History (19)
#1
@
15 years ago
- Keywords has-patch needs-testing added; media thumbnail removed
- Version 2.9.1 deleted
#2
@
15 years ago
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.
#3
@
10 years ago
Came across this ticket, as I need some images always to create a thumbnail/image size. Has this been incorporated?
#6
@
10 years ago
I think we should just scale up images when cutting a crop and the original is smaller than the size, and avoid this issue completely.
#8
@
10 years ago
The fact that a thumb size in cases like @atow described in the original report is a bummer. Instead of not generating image sizes bigger than the original, we should scale up so that these cuts are generated. Whether they are pixelated shouldn't be WordPress' business, which I'm guessing was the idea behind not creating the bigger cuts.
image_make_intermediate_size()
is the public function for resizing an image. Although there are also public methods on the WP_Image_Editor_* instance, image_make_intermediate_size()
is a façade layer for this.
image_resize_dimensions()
seems to be the place where logic to do regarding resizing, as it generates the parameters for imagecopyresampled()
, so I've modified some of this logic.
attachment:12120.diff is a go at this.
image_resize_dimensions()
has been modified to default to upscaling images.
I've also created a new function, wp_scale_dimensions()
, which is wp_constrain_dimensions()
but with an option for upscaling. wp_constrain_dimensions()
now calls wp_scale_dimensions()
with a disallow upscaling flag for backwards compatibility. We could've jammed this logic into wp_constrain_dimensions()
, but it seems apt to make a separate, more self-describing function with the extra option.
I added a unit test and modified old ones which expected images not to be scaled up.
#9
@
10 years ago
- Summary changed from Force Media Image Generation (for thumbnails) to Thumbnail image isn't created if the original is too small
#10
@
10 years ago
- Priority changed from normal to low
- Type changed from enhancement to feature request
#11
@
10 years ago
- Keywords needs-testing removed
@ericlewis's patch tested on WordPress 4.1 and WordPress 3.9
uploading image with original size 250x50
Without the patch: two files are generated the original one and orginal-150x50
Results after applying the patch:
4 files are generated:
original
original-150x50
original-300x60
original-1024x205
#15
@
10 years ago
- Milestone changed from 4.2 to Awaiting Review
Needs a refresh, and also I really hate the idea of scaling images up in a file by default. I'd rather point the thumbnail size to the full size or something. If I'm uploading a small icon, the last thing I want is upscaled, likely significantly larger files (antialiasing, etc.) that I'll never use.
#16
@
9 years ago
- Keywords needs-patch added; has-patch needs-refresh removed
Agree with Helen here, upscaling an image sounds like a really bad idea.
#17
@
20 months ago
- Keywords close added; needs-patch removed
- Resolution set to wontfix
- Status changed from new to closed
we should close this ticket IMO
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.