View Single Post
Old 09-30-2007, 12:05 PM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I use the following function, but I wrote it almost a year ago now so it may not be the best way of doing it. You've got to remember though that manipulating images is an intensive task in itself.

PHP Code:
function doResize($szSource$szDestination$szExtension$iResizeWidth$iResizeHeight)
{
    declare(
ticks 1)
    {
        
$szExtension strtolower($szExtension);
        
         switch(
$szExtension)
         {
             case(
'jpg'):     $pSource imagecreatefromjpeg($szSource); break;
             case(
'jpeg'):     $pSource imagecreatefromjpeg($szSource); break;
             case(
'gif'):     $pSource imagecreatefromgif($szSource); break;
             case(
'wbmp'):     $pSource imagecreatefromwbmp($szSource); break;
             case(
'png'):     $pSource imagecreatefrompng($szSource); break;
         }
         
         
$pResized imagecreatetruecolor($iResizeWidth$iResizeHeight);
         list(
$iWidth$iHeight) = getimagesize($szSource);
        
         if(!
imagecopyresampled($pResized$pSource0000$iResizeWidth$iResizeHeight$iWidth$iHeight))
         {
             return 
false;    
         }

        switch(
$szExtension)
        {
             case(
'jpg'):     $pResult imagejpeg($pResized$szDestination100); break;
             case(
'jpeg'):     $pResult imagejpeg($pResized$szDestination100); break;
             case(
'gif'):     $pResult imagegif($pResized$szDestination); break;
             case(
'wbmp'):     $pResult imagewbmp($pResized$szDestination); break;
             case(
'png'):     $pResult imagepng($pResized$szDestination); break;
         }
         
        if(
$pResult)
        {
            return 
true;
        }
            
        return 
false;
    }

__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote