Jump to content


Photo

resizetofile() no longer working


  • Please log in to reply
1 reply to this topic

#1 someguywhoskis

someguywhoskis
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 30 September 2006 - 04:28 PM

Hi, It's been forever since I've written an image upload script, and back when I did, the version of PHP supported resizetofile(), and apparently, that doesn't work anymore.

I have the statement:

resizetofile("$temppath",$picwsize,$pichsize,"$filepath");

And I've tried to use imagecopyresampled, but with no success.  Can someone point me in the right direction, and maybe using those variables, put it into a working resizing function, because I can't seem to figure it out.  Thanks so much!

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 30 September 2006 - 05:52 PM

If I recall that function is part of the BlueShoes PHP core framework, class -> Bs_ImageUtil!

All it does is create a thumbnail in the size you pass (param[0] -> source file, param[1] -> maximum width, param[2] -> maximum height, param[3] -> out file, param[4] (optional -> jpg quality) )


So something like this should do the same thing!

function resizetofile ( $source, $wm, $hm, $out, $quality = 75 )
{
	$ext = strtolower ( substr ( $source, ( strrpos ( $source, '.' ) + 1 ) ) );

	switch ( $ext )
	{
		case 'gif' :
		$old = imagecreatefromgif ( $source );
		break;
		case 'jpg' :
		$old = imagecreatefromjpeg ( $source );
		break;
		case 'png' :
		$old = imagecreatefrompng ( $source );
		break;
		default:
		return ( false );
	}

	list ( $ow, $oh ) = getimagesize ( $source );

	$or = ( $ow / $oh );

	if ( $wm / $hm > $or )
	{
		$wm = ( $hm * $or );
	}
	else
	{
		$hm = ( $wm / $or );
	}

	$new = imagecreatetruecolor ( $wm, $hm );

	imagecopyresampled ( $new, $old, 0, 0, 0, 0, $wm, $hm, $ow, $oh );

	switch ( $ext )
	{
		case 'gif' :
		imagegif ( $new, $out );
		break;
		case 'jpg' :
		imagejpeg ( $new, $out, $quality );
		break;
		case 'png' :
		imagepng ( $new, $out );
		break;
	}

	imagedestroy ( $old );
	imagedestroy ( $new );

	return ( true );
}


me!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users