This is a discussion on Using GD/Image Functions to Transform Images Stored in a Database within the PHP Language forums, part of the PHP Programming Forums category; I'm new to the GD/Image functions with PHP, and I'm trying to use them to manipulate jpeg ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'm new to the GD/Image functions with PHP, and I'm trying to use them
to manipulate jpeg images that I've stored in a MySQL database (specifically, creating thumbnails). The thing I can't tell from reading the documentation is how to use these image functions to operate on image data -- it looks like you get a GD image resource in each case by specifying a file name, not by passing image data directly. While I can see how that's convenient for the common case, I can't figure out how to make this work without writing the image out to a file (and since I'm already taking a bit of a performance hit by reading the image out a database, that seems like the wrong thing to do). Can anyone elaborate? |
|
|||
|
notsew-reversePreceedingAndRemoveThis@canncentral.org (Weston C) wrote in message news:<df41fe1.0309130905.2f7cccc6@posting.google.c om>...
> I can't tell from > reading the documentation is how to use these image functions to > operate on image data As it turns out, the helpful folks on php-general suggested the function "imagecreatefromstring", which seems to be the ticket. However, I'm having another problem. The end goal is to create a script that will output the image to the browser -- and will resize it if given a width value via the query string. Right now, I have a script that works if I just pass the image through, but it fails if I try to use the gd library to change the size. Here's what I've got: $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?tabl...field=Picture1 and http://www.fsboutah.net/jpg.php?tabl...ure1&width=100 for contrasts. -W |