Hi,
I am writing an eCommerce site for a client and when showing products i wish to show a thumbnail which is generated on the fly from a picture. It works, but not totally correctly. This is my code (I borrowed it from somewhere and tweaked it slightly)

PHP Code:

<?php

    $error 
False;
    
    
$system explode("."$image);
    
    
// check if the 'image' parameter has been given
    
if (!isset($image)) // if not generate an error
        
$error True;
        
    
// check if the 'img_size' parameter has been given
    
if (!isset($img_size) && ($resize != 'no')) // if not generate an error
        
$error True;
    
    if(
$resize != 'no')    {
        
// ensure that $img_size is an integer 
        
$img_size = (integer) $img_size;
        
        
// check that the size asked for is sensible
        
if ($img_size 20)// if not generate an error
            
$error True;    
    }
    
    if(!
$bigimage=@imagecreatefromjpeg($image))
    
$error true;        

    
    if(
$error){ // generate an error image
        
$img ImageCreate(123100);                
        
$bg ImageColorAllocate($img255255255);
        
$white ImageColorAllocate($img25500);
        
ImageString($img53020"Picture"$white);
        
ImageString($img54540"Not"$white);
        
ImageString($img52560"Available"$white);
        
ImagePNG($img);
        
ImageDestroy($img);
        exit();
    }
    
    
$x=imageSX($bigimage);
    
$y=imageSY($bigimage);        
    
    if(
$resize == 'no' || (($x $y) && ($x $img_size)) || (($y $x) && ($y $img_size))){

        
imagejpeg($bigimage);
        exit();
    }
    
    
// find the larger dimension
    
if ($x>$y) {    // if it is the width then
        
$dx 0;                    // the left side of the new image
        
$w $img_size;                // the width of the new image
        
$h = ($y $x) * $img_size;    // the height of the new image
        
$dy 0;                    // the top of the new image
    
} else {    // if the height is larger then
        
$dy 0;                    // the top of the new image
        
$h $img_size;                // the height of the new image
        
$w = ($x $y) * $img_size;    // the width of the new image
        
$dx 0;    // the left edgeof the new image
    
}
    
    
$tnimage ImageCreate($w$h);    

    
ImageCreateTrueColor($w$h);
    
ImageCopyResampled($tnimage$bigimage$dx$dy00$w$h$x$y); 
        
    
// copy the resized version into the thumbnal image
    //ImageCopyResized($tnimage, $bigimage, $dx, $dy, 0, 0, $w, $h, $x, $y);    

    
imagejpeg($tnimage);    

    
// release the memory used by the thumbnail image
    
ImageDestroy($tnimage);
    
    
// release the memory used by the original big image
    
ImageDestroy($bigimage);
    

?>
And this is the result:



This is what it should look like:



Any ideas where i might be going wrong?
Thanks for the help

-Pointybeard