I have an old site up that is storing the images straight in the database, (Of course as BLOBS).
The initial site design isn't the best, it just resizes the image in the <img src> tag.
There are about 100 pictures in the database now, and what I want to do is read them from the database, create a thumbnail, and store it (the thumbnail) in a directory and the path to the thumb in the database.
Shouldn't be rocket science!
I have it working perfectly when you upload a picture from the form (add a new image), before the data is put into the database. But for my "update" script I can't seem to get it to work.
I keep getting " getimagesize: Unable to open 'Resource id #3' for reading."
Here's my code:
In the database, I'm storing an id - id_files, the binary data - bin_data, filename - filename, filesize -filesize, filetype - filetype, some foreign key stuff, and the path to the thumbnail.
The thumbnail part works, if I can get past the imagecreatefromstring, and the getimage size on the picture from the database! * Working with GD 1.6
while ($a_row = mysql_fetch_array($getallimages))
{
$lastid = $a_row[id_files];
$binFile = imagecreatefromstring("$a_row[bin_data]");
$thumbFile = "../prop_thumbs/$lastid.jpg";
$updater = "UPDATE tbl_Files SET thumb_data = '$thumbFile' WHERE id_Files = '$lastid'";
if (!mysql_query ($updater, $link) )
{
die (mysql_error());
}
$image_url = "$binFile";
$size = getimagesize($image_url);
$ow = $size[0]; // Index 0
$oh = $size[1]; // Index 1
$type = $size[2]; // Index 2
$imgsrc_tag = $size[3]; // Index 3
$channels = $size['channels'];
$bits = $size['bits'];
$mime = $size['mime'];
$w = 120;
$h = 120;
if ($ow > $oh)
{
$new_w = $w;
$new_h = floor($new_w * $oh / $ow);
}
else if ($oh > $ow)
{
$new_h = $h;
$new_w = floor($new_h * $ow / $oh);
}
$dst_img=ImageCreate($new_w,$new_h);
$src_img=ImageCreateFromJPEG($binFile);
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
if (!ImageJPEG($dst_img, "../prop_thumbs/$lastid.jpg"))
{
print "Didn't Work <BR>";
}
else
{
print "Worked<BR>";
$i++;
}
}
Thanks for the help!