[wp-trac] [WordPress Trac] #12120: Force Media Image Generation (for thumbnails)
WordPress Trac
noreply at wordpress.org
Sat Mar 22 12:58:03 UTC 2014
#12120: Force Media Image Generation (for thumbnails)
-------------------------------------+-----------------------------
Reporter: atow | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Media | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-testing | Focuses:
-------------------------------------+-----------------------------
Old 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;
New 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;
}}}
--
Comment (by SergeyBiryukov):
Related: #15311, #21295.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/12120#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list