Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could resize and add a <a href="http://en.wikipedia.org/wiki/Letterbox" rel="nofollow noreferrer">letterbox</a> if required. You simply need to resize the width and then calculate the new height (assuming width to height ratio is same as original) then if the height is not equal to the preferred height you need to draw a black rectangle (cover background) and then centre the image.</p> <p>You could also do a pillarbox, but then you do the exact same as above except that width becomes height and height becomes width.</p> <p><strong>Edit:</strong> Actually, you resize the one that is the biggest, if width is bigger, you resize that and if height is bigger then you resize that. And depending on which one you resize, your script should either letterbox or pillarbox.</p> <p><strong>EDIT 2:</strong></p> <pre><code>&lt;?php // Define image to resize $img_src = $_FILES['galleryimg']['tmp_name']; $thumb = "../gallery/" . rand(0,100000) . ".jpg"; // Define resize width and height $width = 500; $height = 636; // Open image $img = imagecreatefromjpeg($img_src); // Store image width and height list($img_width, $img_height) = getimagesize($img_src); // Create the new image $new_img = imagecreatetruecolor($width, $height); // Calculate stuff and resize image accordingly if (($width/$img_width) &lt; ($height/$img_height)) { $new_width = $width; $new_height = ($width/$img_width) * $img_height; $new_x = 0; $new_y = ($height - $new_height) / 2; } else { $new_width = ($height/$img_height) * $img_width; $new_height = $height; $new_x = ($width - $new_width) / 2; $new_y = 0; } imagecopyresampled($new_img, $img, $new_x, $new_y, 0, 0, $new_width, $new_height, $img_width, $img_height); // Save thumbnail if (is_writeable(dirname($thumb))) { imagejpeg($new_img, $thumb, 100); } // Free up resources imagedestroy($new_img); imagedestroy($img); ?&gt; </code></pre> <p>Sorry it took a while, I ran across a small bug in the calculation part which I was unable to fix for like 10 minutes =/ This should work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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