Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe this is what you're looking for; specifically, the pictures in the middle column:</p> <p><img src="https://lh5.ggpht.com/-5CpssUlhKK8/TZBbxu2QabI/AAAAAAAABPg/KhEUUSDZey8/crop-case-wider.png" alt="When source image is wider"> <img src="https://lh3.ggpht.com/-edEGRtSPxqk/TZBbx_FvCCI/AAAAAAAABPo/y4D_ZQ0Zey0/crop-case-taller.png" alt="When source image is taller"> <img src="https://lh4.ggpht.com/-Bc8Ml6smcSk/TZBbxnaLFaI/AAAAAAAABPY/uM1pqNGM9ww/crop-case-same.png" alt="When aspect ratios are same"></p> <p>Following code is derived from <a href="http://salman-w.blogspot.com/2009/04/crop-to-fit-image-using-aspphp.html" rel="nofollow noreferrer">Crop-To-Fit an Image Using ASP/PHP</a>:</p> <pre><code>list( $source_image_width, $source_image_height ) = getimagesize( '/path/to/image' ); $target_image_width = 400; $target_image_height = 300; $source_aspect_ratio = $source_image_width / $source_image_height; $target_aspect_ratio = $target_image_width / $target_image_height; if ( $target_aspect_ratio &gt; $source_aspect_ratio ) { // if target is wider compared to source then // we retain ideal width and constrain height $target_image_height = ( int ) ( $target_image_width / $source_aspect_ratio ); } else { // if target is taller (or has same aspect-ratio) compared to source then // we retain ideal height and constrain width $target_image_width = ( int ) ( $target_image_height * $source_aspect_ratio ); } // from here, use GD library functions to resize the image </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload