> From: andy [mailto:[EMAIL PROTECTED]]

> Hi there,

Hey, Andy.

> I am wondering how to resize an image which is stored in a 
> mysql blob field.
> With files this workes just fine, but how to do this with the 
> image comming from blob? Has anybody done this already?

Incidentally, I've done this just yesterday.

First download the image, write it to the directory and then proceed as you will. It 
uses ImageMagick, 'cause my ISP still doesn't install GD 2.x.

Here it goes (I use the ADODB library using MySQL), and in fact, if someone can 
optimize it, it would be welcome :^)

$rsColegio = $conn->Execute("SELECT * FROM ConEsc_Colegio WHERE Colegio_Id='" . 
$rs->Fields("Colegio_Id") . "'") or die("Algo paso en los colegios...");
if (stristr($rsColegio->Fields("Colegio_Imagen_Tipo"), "gif") != "")
        $fileext = ".gif";
elseif (stristr($rsColegio->Fields("Colegio_Imagen_Tipo"), "jpeg") != "")
        $fileext = ".jpg";
elseif (stristr($rsColegio->Fields("Colegio_Imagen_Tipo"), "jpg") != "")
        $fileext = ".jpg";
else
        $fileext = "";
if ($fileext != "") {
        $image_tmpfilename = "images/tmp_" . $rsColegio->Fields("Colegio_Id") . 
$fileext;
        $image_filename = "images/" . $rsColegio->Fields("Colegio_Id") . $fileext;
        $file = fopen("$image_tmpfilename", "w") or die("No fue posible abrir el 
archivo");
        if (!$file)
                echo "<td>No se pudo abrir el archivo.</td>\n";
        else {
                fputs($file, $rsColegio->Fields("Colegio_Imagen"));
                fclose($file);
        }
        $aSize = getimagesize($image_tmpfilename);
        $iWidth = $aSize[0];
        $iHeight = $aSize[1];
        if (($iWidth >= 120) || ($iHeight >= 85)) {
                if ($iWidth > $iHeight)
                        $fPercent = $iWidth / 120;
                else
                        $fPercent = $iHeight / 85;
                $newWidth = $iWidth / $fPercent;
                $newHeight = $iHeight / $fPercent;
                system("convert -antialias -sample " . $newWidth . "x" . $newHeight . 
" $image_tmpfilename $image_filename"); 
        }
        else
                copy($image_tmpfilename, $image_filename);
        unlink($image_tmpfilename);
}
else
        $image_filename = "images/sinlogo.jpg";

Hope that helps.
--
Un gran saludo/Big regards...
   Arturo Barajas
   Sistemas PPG SJR
   +52 (427) 271-9100, ext. 448

> -----Original Message-----
> Sent: Jueves, 04 de Julio de 2002 11:25 a.m.
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: [PHP] resizing images comming out of blobs
> 
> 
> 
> 
> Thank you for any help on that,
> 
> andy
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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

Reply via email to