Jump to content

Thumbnail resizing to exact size.


scraptoft

Recommended Posts

Hi, Can I change my thumbnail creator script to resize the thumbnails to [b]exact sizes[/b]? As it is it creates the thumbnail by percentage of width and height(?).

Here is my code:
[code]
  //get the dimensions for the thumbnail
  $thumb_width = $width * 0.30;
  $thumb_height = $height * 0.30;

  //create the thumbnail
  $largeimage = imagecreatefromjpeg($newfilename);
  $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
  imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0,
                    $thumb_width, $thumb_height, $width, $height);
  imagejpeg($thumb, $newthumbname);
  imagedestroy($largeimage);
  imagedestroy($thumb);
[/code]

Any suggestions on how to do this? I would like all of my thumbnails creating to 55x55 pixels.

Cheers
Link to comment
Share on other sites

Thanks for the link, here is what I have came up with so far:
[code]    //"convert" the image to jpg
    $maxwidth = 100;
    $maxheight = 400;
    if (($width>$maxwidth) OR ($height>$maxheight)) (
        $image_jpg = imagecreatetruecolor($width, $height);
    imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0,
                     $maxwidth, $maxheight, $maxwidth, $maxheight);
    )else (
    $image_jpg = imagecreatetruecolor($width, $height);
    imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0,
                     $width, $height, $width, $height);)
                         imagejpeg($image_jpg, $newfilename);
    imagedestroy($image_old);
    imagedestroy($image_jpg);
  }[/code]

I'm getting a Parse error: syntax error, unexpected ';' . Anyone see why?
Link to comment
Share on other sites

try this ok.
[code]
    
//"convert" the image to jpg

$maxwidth = 100;

$maxheight = 400;

if (($width>$maxwidth) OR ($height>$maxheight)) {

$image_jpg = imagecreatetruecolor($width, $height);

imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $maxwidth, $maxheight, $maxwidth, $maxheight);
    
}else{

$image_jpg = imagecreatetruecolor($width, $height);

imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);

(imagejpeg($image_jpg, $newfilename);

imagedestroy($image_old);

imagedestroy($image_jpg);

}

[/code]
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.