resize images on the fly.

    Date: 03/24/07 (PHP Community)    Keywords: database

    I've been testing out image uploading and resizing on the fly tonight..
    While I have the page able to pull the image name from the database. It seems like the script I've found can't display the picture, as a variable, the 'imagejpeg' shows the image fine but how do I end the script so that I can have the sized image name in a variable.




            $gvsql = "SELECT * FROM image_gallery WHERE gid = \"$gid\" 
                                 ";
            $gvresult = @mysql_query($gvsql,$conn) or die("Couldn't execute query.");
     
            while ($gvrow = mysql_fetch_array($gvresult)) {
             
                             $img = $gvrow['image_name_resize'];
                                     
                                            }
                                           
            $filename = '/home/benjamin/www/dev/upload/';

            $width = 300;
            $height = 300;

            header('Content-type: image/jpeg');

              $filefile="$filename$img";
            list($width_orig, $height_orig) = getimagesize($filefile);

            $ratio_orig = $width_orig/$height_orig;

            if ($width/$height > $ratio_orig) {
               $width = $height*$ratio_orig;
            } else {
               $height = $width/$ratio_orig;
            }
            $image_p = imagecreatetruecolor($width, $height);
            $image = imagecreatefromjpeg($filefile);
            imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
            imagejpeg($image_p, null, 100);
            imagedestroy($image_p);
    ?>

    Source: http://community.livejournal.com/php/556781.html

« Totally unrelated; but... || Retouching on the redirect »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home