Make WordPress Core

Opened 14 years ago

Closed 16 months ago

Last modified 16 months ago

#12120 closed feature request (wontfix)

Thumbnail image isn't created if the original is too small

Reported by: atow's profile atow Owned by:
Milestone: Priority: low
Severity: normal Version:
Component: Media Keywords: close
Focuses: Cc:

Description (last modified by SergeyBiryukov)

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)

force_image_resize.diff (5.2 KB) - added by Kanuck54 14 years ago.
12120.diff (10.7 KB) - added by ericlewis 9 years ago.

Download all attachments as: .zip

Change History (19)

#1 @Kanuck54
14 years ago

  • Keywords has-patch needs-testing added; media thumbnail removed
  • Version 2.9.1 deleted

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.

#2 @Kanuck54
14 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 @landwire
10 years ago

Came across this ticket, as I need some images always to create a thumbnail/image size. Has this been incorporated?

#4 @SergeyBiryukov
10 years ago

  • Description modified (diff)

Related: #15311, #21295.

#5 @landwire
10 years ago

Ah, thanks. The related tickets help and are more up to date.

#6 @ericlewis
9 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.

Last edited 9 years ago by ericlewis (previous) (diff)

#7 @ericlewis
9 years ago

  • Milestone changed from Future Release to 4.2

9 years ago

#8 @ericlewis
9 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 @ericlewis
9 years ago

  • Summary changed from Force Media Image Generation (for thumbnails) to Thumbnail image isn't created if the original is too small

#10 @DrewAPicture
9 years ago

  • Priority changed from normal to low
  • Type changed from enhancement to feature request

#11 @alordiel
9 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:

#12 @SergeyBiryukov
9 years ago

#13014 was marked as a duplicate.

#14 @wonderboymusic
9 years ago

  • Keywords needs-refresh added

The patch is exploding

#15 @helen
9 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 @swissspidy
8 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 @Mista-Flo
16 months ago

  • Keywords close added; needs-patch removed
  • Resolution set to wontfix
  • Status changed from new to closed

we should close this ticket IMO as Helen and Pascal stated it doesn't sound something that Core should support

Last edited 16 months ago by Mista-Flo (previous) (diff)
Note: See TracTickets for help on using tickets.