Jump to content

resizetofile() no longer working


someguywhoskis

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.