someguywhoskis Posted September 30, 2006 Share Posted September 30, 2006 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:[code]resizetofile("$temppath",$picwsize,$pichsize,"$filepath");[/code]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! Quote Link to comment Share on other sites More sharing options...
printf Posted September 30, 2006 Share Posted September 30, 2006 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![code=php:0]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 );}[/code]me! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.