Jump to content

Resising ratio


graham23s

Recommended Posts

Hi Guys,

 

i have written this function to resize a .jpg, i understan all aspects of the code apart from how to keep the aspect ration (height wise) could anyone tell me how to work out the correct aspect ratio at all

 

code:

 

<?php
function resize_image($upload_directory, $new_image_name)
{
  // original image location //
  $original_image = $upload_directory;
  
  // set up a canvas my babies //
  $canvas_width = 65;
  $canvas_height = 65;
  
  // create the canvas //
  $canvas = imagecreatetruecolor($canvas_width, $canvas_height);
  
  // get the image height and width //
  list($image_width, $image_height) = getimagesize($upload_directory);
  
  // new sizes // 
  $new_image_width = 65;
  // STUCK HERE //
  
  // store original into memory //
  $original_image = imagecreatefromjpeg($original_image);
  
  // copy the original image onto the canvas canvas, original and top/left co-ordinates //
  imagecopyresampled($canvas, $original_image, 0,0,0,0, $new_image_width, $new_image_height, $image_width, $image_height);
  
  // thumbnail name //
  $new_thumbnail_name = "thumb-$new_image_name";
  
  // save the thumbnail in the thumbs folder //
  if(imagejpeg($canvas, "products/thumbnails/$new_thumbnail_name", 100))
  {
   return("$new_thumbnail_name");
  }
  
}
?>

 

thanks guys

 

Graham

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.