Goins Posted May 22, 2008 Share Posted May 22, 2008 I want the thumbnail to be a certain size such as 150X150? Not sure how to change it tho. function make_thumbnail($img, $thmb, $w, $h) { list($width, $height) = getimagesize($img); $new_width = ($width > $w) ? $w : $width; $new_height = ($height > $h) ? $h : $height; $ext = explode( ".", $img ); $ext = strtolower( $ext[count( $ext )-1] ); switch ($ext) { case 'gif': $type = 'gif'; break; case 'jpg': $type = 'jpeg'; break; case 'jpeg': $type = 'jpeg'; break; case 'png': $type = 'png'; break; } $image_p = imagecreatetruecolor($new_width, $new_height); switch( $type ) { case 'gif': $image = imagecreatefromgif($img); break; case 'jpeg': $image = imagecreatefromjpeg($img); break; case 'png': $image = imagecreatefrompng($img); break; } $white = imagecolorallocate($image_p, 255, 255, 255); imagefill($image_p, 1, 1, $white); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); switch ($type) { case 'gif': imagegif($image_p, $thmb); break; case 'jpeg': imagejpeg($image_p, $thmb, 100); break; case 'png': imagepng($image_p, $thmb); break; } } $pre_action = explode(";", $_GET['opt']); $action = $pre_action[0]; foreach ( $pre_action as $a => $b ) { if ( $a > 0 ) { $sub_action[] = $pre_action[$a]; } } ?> Link to comment https://forums.phpfreaks.com/topic/106794-php-thumbnail/ Share on other sites More sharing options...
soycharliente Posted May 22, 2008 Share Posted May 22, 2008 It looks like the function takes in the width and height as a parameter. Link to comment https://forums.phpfreaks.com/topic/106794-php-thumbnail/#findComment-547459 Share on other sites More sharing options...
Goins Posted May 23, 2008 Author Share Posted May 23, 2008 So how dose it decide on what the thumbnail width and height is going to be? ??? Link to comment https://forums.phpfreaks.com/topic/106794-php-thumbnail/#findComment-547810 Share on other sites More sharing options...
Goins Posted May 23, 2008 Author Share Posted May 23, 2008 Anyone I really need this last part! :'( Link to comment https://forums.phpfreaks.com/topic/106794-php-thumbnail/#findComment-547855 Share on other sites More sharing options...
DarkerAngel Posted May 23, 2008 Share Posted May 23, 2008 This is an expert of a code I wrote a Long time ago you can play with it as you wish <?php if(($imagetype == 'jpg') or ($imagetype == 'jpeg')) { $image = ImageCreateFromJPEG($imagefile); $dem = getimagesize($imagefile); if($dem['0'] < $dem['1']) { $rate = $dem['1'] / 200; $rsiz = array( 0 => $dem['0'] / $rate, 1 => 200); } else if($dem['0'] > $dem['1']) { $rate = $dem['0'] / 200; $rsiz = array( 0 => 200, 1 => $dem['1'] / $rate); } else if($dem['0'] == $dem['1']) { $rsiz = array( 0 => 200, 1 => 200); } else { die('Size Calculation Error'); } $im = imagecreatetruecolor($rsiz[0], $rsiz[1]) or die('Error Creating Image'); imagecopyresampled($im, $image, 0, 0, 0, 0, $rsiz[0], $rsiz[1], $dem[0], $dem[1]) or die('Resize Error'); header("Content-type: image/jpeg"); imagejpeg($im); imagedestroy($immage); imagedestroy($im); } ?> You see all the 200's that was my thumbnail size and it keeps proper ratio, it also increases size if it was under 200px Link to comment https://forums.phpfreaks.com/topic/106794-php-thumbnail/#findComment-547868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.