I am trying to create a piece of code that will create and display
thumbnail image. When trying to send the image to a browser, I see
binary data rather then an image. You can see the problem at
www.dallypost.com/a/test.php

The troubled cose for this page follows:

<?PHP

//a master image may be any image of any size

//If the master image exists, the thumb will be created and output to
the browser

//requires path from the file system home directory as
$master_image_path

//requires the name of the master image as $master image        
        

//test variables -- will eventually be defined by the calling module
$master_image_path = "/home/html/74ranch/uploads/";
$master_image = "chex34.jpg";



if(!isset($thumb_width))
{
        $thumb_width = 80;
}//end if


//make sure that the master file exists
$master_image_all = "$master_image_path";
$master_image_all .= "$master_image";

//remove this section after coding is complete
        $master_image_all_link = "/74ranch/uploads/";
        $master_image_all_link .= "$master_image";
        print("<img src = $master_image_all_link>");

if(file_exists($master_image_all))
{
        $size = getimagesize("$master_image_all");
        $width = $size[0];
        $height = $size[1];
        

                //calculate thumb height
                $factor = $width / $thumb_width;
                $thumb_height = $height * $factor;
                $thumb_height = $thumb_height * .1;
                $thumb_height = round($thumb_height);
                print("<P> Origional: height: $height width:            
$width<BR>Target:
height:$thumb_height width:             $thumb_width<P>");
                                
                //build the thumbnail 
                $src_img = imagecreatefromjpeg("$master_image_all");
                $dst_img = imagecreate($thumb_width,$thumb_height);
                //$dst_img =
                imagecreatetruecolor($thumb_width,$thumb_height);//requires            
 gd 2.0
or higher
                
                print("<P>Variables that will be inserted into the              
imagecopyresized
function");
                print("<BR>width: $width");
                print("<br>height $height");
                print("<br>thumb_width $thumb_width");
                print("<br>thumb_height $thumb_height");
                
                print("<P>Display the new thumb image<P>");
                
                imagecopyresized($dst_img, $src_img, 0, 0, 0, 0,                
$thumb_width,
$thumb_height, $width, $height);
                
                
                //imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0,            
$thumb_width,
$thumb_height, $width, $height);//requires gd           2.0 or higher
                
                
                //imagejpeg($dst_img, "path and file name", 75);//saves                
 the image to
a file
                
                imagejpeg($dst_img, '', 50);//sends the image to the            browser
                
                imagedestroy($src_img);
                imagedestroy($dst_img); 

        

}//end if
?>




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to