Jump to content

Archived

This topic is now archived and is closed to further replies.

scraptoft

Thumbnail resizing to exact size.

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

Share this post


Link to post
Share on other sites
This might help...

[a href=\"http://www.nstoia.com/toh/technical/imageresize/\" target=\"_blank\"]http://www.nstoia.com/toh/technical/imageresize/[/a]

Lite...

Share this post


Link to post
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?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
I'm getting a Parse error: syntax error, unexpected $end. But can't find any curly brackets that havn't been closed. I'm hoping its only somthing minor.

Share this post


Link to post
Share on other sites

×

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.