Jump to content

Archived

This topic is now archived and is closed to further replies.

someguywhoskis

resizetofile() no longer working

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.