[wp-trac] [WordPress Trac] #32313: Image upscale as Media's settings option

WordPress Trac noreply at wordpress.org
Fri May 8 13:58:13 UTC 2015


#32313: Image upscale as Media's settings option
----------------------------+-----------------------------
 Reporter:  odie2           |      Owner:
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Media           |    Version:  trunk
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 Hello,

 I had to searching for hours to find image upscale (because unusually
 keyword for me as non-English). I am creating new school's website and
 custom featured images are up to 1200px width (in fact ~876px when with
 sidebar), however old images are only 800px width and I had problem with
 deal it.

 I found so simple solution to set image to required width/height if not
 enought, then crop.


 {{{
 /*  Thumbnail upscale
 /* ------------------------------------ */
 function alx_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w,
 $new_h, $crop ){
     if ( !$crop ) return null; // let the wordpress default function
 handle this

     $aspect_ratio = $orig_w / $orig_h;
     $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);

     $crop_w = round($new_w / $size_ratio);
     $crop_h = round($new_h / $size_ratio);

     $s_x = floor( ($orig_w - $crop_w) / 2 );
     $s_y = floor( ($orig_h - $crop_h) / 2 );

     return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int)
 $new_h, (int) $crop_w, (int) $crop_h );
 }
 add_filter( 'image_resize_dimensions', 'alx_thumbnail_upscale', 10, 6 );
 }}}
 [http://alxmedia.se/code/2013/10/thumbnail-upscale-correct-crop-in-
 wordpress/]

 In my opinion it should be included as option for each/globally for image
 sizes in Media's settings page and also as fifth parameter for
 add_image_size(), because this can make big headache.

 Greetings

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32313>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list