Jump to content


Photo

Can you help fix my thumbnailing, it's distorting


  • This topic is locked This topic is locked
2 replies to this topic

#1 alwaysinit

alwaysinit
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 25 October 2006 - 02:32 PM

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:
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;
}


#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 October 2006 - 03:10 PM

I'll post some code that I use, I specify a maximum width and a maximum height and it resizes accordingly.  Would that help?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 alwaysinit

alwaysinit
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 25 October 2006 - 05:22 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users