I'm trying to show a thumbnail of a picture store in a longblob field into a database.

I could use imagemagik and gd, but i don't know how i can do that.

Can anyone help me?

Thanks

    This is a small script I use for thumbnail creation.

    Step 1:
    Put this code in a separate file, i.e. "thumbmaker.pnp":
    <?
    // Headers make the browser cache the image
    Header ("Content-type: image/png");
    Header ("Last-Modified: " . gmdate("D, d M Y H:i:s",mktime (0,0,0,1,1,2000)) . " GMT");
    Header ("Expires: Mon, 26 Jul 2040 05:00:00 GMT");
    Header ("Cache-Control: max-age=10000000, s-maxage=1000000, proxy-revalidate, must-revalidate");

    // Open the original file that you want to make the thumb from
    // the variable $originalfil is passed by a url querystring.
    $seis = getImageSize($originalfil);
    $original = imagecreatefromjpeg($originalfil);

    // Specify height and width of your thumbnail
    $h = 54;
    $w = 72;

    $xyrelation = $seis[0] / $seis[1];
    $maalestokk = $seis[1] / $h;
    $br = round($seis[0] / $maalestokk);

    if ($br > $w) {
    $br = $w;
    $h = round($br / $xyrelation);
    }

    $thumb = imagecreatetruecolor($br, $h);

    imagecopyresampled ( $thumb, $original, 0, 0, 0, 0, $br, $h, $seis[0], $seis[1]);
    imagetruecolortopalette ( $thumb, false, 64); // reduces color depth so that the png output file is smaller. Note that the png thumbnails are MUCH smaller than jpegs of the same pixel size!

    ImagePng($thumb);

    imagedestroy($original);
    imagedestroy($thumb);

    ?>

    Step 2: In your image tag you put src="thumbmaker.php?originalfil=XXX".

    Hope this works. Beware of typos, I have translated most of my variable names from Norwegian.

    Helsing Torstein

      Thanks for the code, i will tray, but what about if i get the image from a blob field in a database? i don't have a .jpg file in my server.

      EDITED:

      I try it and it doesn't work for me, maybe coz i get the image from a blob field of a database.

      Any solution?

        I suppose you have to pass thumbmaker.php an id to the database post that contains your picture, then set up thumbmaker.php to query your database for the image. I haven't tried this, I store my images in jpegs on the server and have only the url strings stored in the database.

          i tried the script using directly a .jpg file upload in my webspace in the same directory of the script and it doesn't work.

          Any solution?

            If you type the url of the thumbmaker.php directly into the adress field of your browser, you can see which error messages php gives you.

              You probably have GD1 installed. You can't use true color under GD1.

                17 days later

                Originally posted by tatoadsl
                Thanks for the code, i will tray, but what about if i get the image from a blob field in a database? i don't have a .jpg file in my server.

                EDITED:

                I try it and it doesn't work for me, maybe coz i get the image from a blob field of a database.

                Any solution?

                Did you ever resolve this?

                I am also having difficulty with the image() functions using a blob image from mysql. Anybody know how to do this?

                  Write a Reply...