I'm trying to write a script that pulls an image from a database and transforms
the size if passed a width via the url query string.

Thanks to the helpful hint about the function "imagecreatefromstring", I 
think I'm now able to ready image data I've pulled for a database with 
GD. However, I'm still having trouble resizing... at least, when I'm 
sending the image to my browser, I'm being told that it "cannot be 
displayed, because it contains errors." (And the script does work if
I don't try resizing... see below for example URL).


Here's what I'm doing:

        $row = mysql_fetch_row($dbresult);
        $imgdata = $row[0];

        if(isset($width) && !empty($width) && is_numeric($width))
        /* only do transformation if given a width */
        {
                $gdimg = imagecreatefromstring($imgdata);
                $srcWidth = imagesx($gdimg);
                $srcHeight = imagesy($gdimg);
                $scaleFactor = $width/$srcWidth;
                $targetHeight = $srcHeight * $scaleFactor;

                $resizedimg = imagecreatetruecolor($width,$targetHeight);
                
imagecopyresized($resizedimg,$gdimg,0,0,0,0,$width,$targetHeight,$srcWidth,$srcHeight);
        }

        header("Content-Type: image/jpeg");
        header("Content-Transfer-Encoding: binary\n");
        //send file contents
        if(!empty($resizedimg)) 
                imagejpg($resizedimg);
        else 
        {
                header("Content-length: " . strlen($imgdata) . "\n");
                print($imgdata);
        }


Does anyone see what I'm doing wrong? Again, the script actually works if I
don't try to do the transform. See:

http://www.fsboutah.net/jpg.php?table=homes&key=4&field=Picture1

and

http://www.fsboutah.net/jpg.php?table=homes&key=4&field=Picture1&width=100

for contrasts.


-W

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

Reply via email to