corillo181 Posted December 28, 2006 Share Posted December 28, 2006 i got this thumbnail makerwhat i want to do is give my thumbnail a specifict height and width how can i do that?this si the code.[code]$save = "albums/tn_".$name;$file = $path; echo "Creating file: $save"; $size = 0.20; list($width, $height) = getimagesize($file) ; $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; [/code] Link to comment https://forums.phpfreaks.com/topic/32030-thumbnail-sp/ Share on other sites More sharing options...
bljepp69 Posted December 28, 2006 Share Posted December 28, 2006 The current code returns an image that is 20% of the original size. So, instead of using the width & height multiplied by this percent, simply state the height and width:[code]$modwidth = 50;$modheight = 50;[/code]However, if you go away from a relative size (like 20%) and only spec in hard numbers for height and width, you might end up with a strange looking thumnail. So, you can use something like the code below to specify a max height and width for your thumbnail and the actual size is still relative to the original.[code]<?php $save = "albums/tn_".$name; $file = $path; echo "Creating file: $save"; list($width, $height) = getimagesize($file) ; $max_width = 50; $max_height = 50; //generating smaller image $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if (($width <= $max_width) && ($height <= $max_height)) { $modwidth = $width; $modheight = $height; } else if (($x_ratio * $height) <= $max_height) { $modheight = ceil($x_ratio * $height); $modwidth = $max_width; } else { $modwidth = ceil($y_ratio * $width); $modheight = $max_height; } $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;?>[/code] Link to comment https://forums.phpfreaks.com/topic/32030-thumbnail-sp/#findComment-148848 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.