Resize and thumbnail with fixed width and variable height

I have a script that uploads an image but first it resizes the image before upload and again to create a thumbnail.
Right now it has a fixed landscape width and height but I realized that some of my uploads will have a longer height. How can I modify my code to make the width fixed but the height will adjust regardless of a landscape or portrait orientation. Here is the parts of the code:

function makeThumbnails($updir, $img){
      $thumbnail_width = 560;
      $thumbnail_height = 432;   ----------------------> This needs to change regardless of orientation
      $new_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
    imagecopyresampled($new_image, $old_image, $dest_x, $dest_y, 0, 0, $new_width, 
     $new_height, $original_width, $original_height);

This is some old code of mine based on a maximum width but you should get the idea.:

// Temporary upload image name
$original_image = '../original_images/flowers.jpg';
// Get the image dimensions
$size=GetImageSize( $original_image );
// Maximum image width
$max_width = '100';
// Maximum image height
//$max_height = '100';
$ratio = 100/$size[0];
$max_height = $size[1]*$ratio;
// Resize the image and save		
$src_img = ImageCreateFromJPEG( $original_image );
$thumbnail = ImageCreateTrueColor( $max_width, $max_height );
ImageCopyResampled( $thumbnail, $src_img, 0, 0, 0, 0, $max_width, $max_height, $size[0],$size[1] );
ImageJPEG( $thumbnail, 'flowers_GD.jpg' );
ImageDestroy( $thumbnail );

Or you could use imagemagick:

exec("convert input -resize 560x output");

You could also use Imagick although I do not use it so you would have to search for the code.

Thank you! Determining the ratio should work.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.