alwaysinit Posted October 25, 2006 Share Posted October 25, 2006 I got this little piece of code from a guy online. It's in my image upload script to create thumbnails when a user uploads an image. As it is now it creates a 150 x 150 square(distorted). I would like it to possibly resize only width, or only height depending on the shape of the image. For instance, if the image is wider than high, then it gets it's width reduced to 150 and the height would be relatively reduced(as to not distort). Then vice-versa for the height.(height 150 x relative width). Instead of display it goes straight into file system and Mysql name value.Can anyone spot what I need to change to get those results(or offer alternative)? Thank you:[code]function create_resize_save_jpeg( $path, $newpath ) { list( $width_orig, $height_orig ) = getimagesize( $path ); $image_p = imagecreatetruecolor( 150, 150); if( !$image = imagecreatefromjpeg( $path ) ) { $_SESSION['errormsg'] = "Cant create photo!"; } else { imagecopyresampled($image_p, $image, 0, 0, 0, 0, 150, 150, $width_orig, $height_orig); imagejpeg($image_p, $newpath, 100); }}function create_resize_save_gif( $path, $newpath ) { list( $width_orig, $height_orig ) = getimagesize( $path ); $image_p = imagecreatetruecolor( 150, 150); if( !$image = imagecreatefromgif( $path) ) { $_SESSION['errormsg'] = "Cant create proto!"; } else { imagecopyresampled($image_p, $image, 0, 0, 0, 0, 150, 150, $width_orig, $height_orig); imagegif($image_p, $newpath, 100); }}function create_resize_save_png( $path, $newpath ) { list( $width_orig, $height_orig ) = getimagesize( $path ); $image_p = imagecreatetruecolor( 150, 150); if( !$image = imagecreatefrompng( $path ) ) { $_SESSION['errormsg'] = "Cant create proto!"; } else { imagecopyresampled($image_p, $image, 0, 0, 0, 0, 150, 150, $width_orig, $height_orig); imagepng($image_p, $newpath, 100); }}function file_extention( $str ) { $size = strlen($str); $x=0; while($x < $size) { if($str[$x] == '.') { $ext = ""; $ext_len = ($size - $x); $y=$x; while($y < $size) { $ext .= $str[$y]; $y++; } } $x++; }return $ext;}[/code] Link to comment https://forums.phpfreaks.com/topic/25060-can-you-help-fix-my-thumbnailing-its-distorting/ Share on other sites More sharing options...
HuggieBear Posted October 25, 2006 Share Posted October 25, 2006 I'll post some code that I use, I specify a maximum width and a maximum height and it resizes accordingly. Would that help?RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/25060-can-you-help-fix-my-thumbnailing-its-distorting/#findComment-114242 Share on other sites More sharing options...
alwaysinit Posted October 25, 2006 Author Share Posted October 25, 2006 thanks huggie, I figured it out. It works good now.lol, But I have a new issue I'm gonna post about now. Maybe I could get your help on that one. Link to comment https://forums.phpfreaks.com/topic/25060-can-you-help-fix-my-thumbnailing-its-distorting/#findComment-114312 Share on other sites More sharing options...
Recommended Posts