Jump to content


Photo

Thumbnail resizing to exact size.


  • Please log in to reply
4 replies to this topic

#1 scraptoft

scraptoft
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 26 June 2006 - 06:38 PM

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

Here is my 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);

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

Cheers

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 26 June 2006 - 07:04 PM

This might help...

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

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 scraptoft

scraptoft
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 26 June 2006 - 08:21 PM

Thanks for the link, here is what I have came up with so far:
    //"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);
  }

I'm getting a Parse error: syntax error, unexpected ';' . Anyone see why?

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 June 2006 - 09:06 PM

try this ok.
    
//"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);

 }


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 scraptoft

scraptoft
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 27 June 2006 - 12:27 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users