469,889 Members | 1,367 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

Resizing uploaded images before inserting as BLOB

Mat
Hi,
I have a system that uploads images as BLOBs in a database. I also
have a function that I use to resize uploaded images before saving as
files. I would like to combine these two by resising the images before
inserting them as BLOBs.
My problem is that (apart from being new to file stuff) my resize
function returns a Resource ID which of course is not the same as the
file handler that was passed to it, it's a reference to an image
created with imagecreate(). The resize function usually uses
imagejpeg() for the final step of creating the file, is there
something similar I need to use to return a file reference for
inserting into the database?

This is the bit that inserts the resized image into the database..

$thisImage = createImageFromSource($fm_image,"",$imgWidth,$imgH eight,"low");
if($thisImage){
$imageData = addslashes(fread(fopen($thisImage, "r"),
filesize($thisImage)));
doQuery("INSERT into
productImages(fileData,fileSize,fileType,productID )
VALUES('".$imageData."','".$thisImage_size."','".$ thisImage_type."','".$fm_productID."');");
}

As you can see, I need createImageFromSource() to return a file
handler into $thisImage that can be used by the fread and fopen
functions. At present createImageFromSource does this (GD 1.6.2):

$src = imagecreatefromjpeg($source);
$dst = imagecreate($tn_width,$tn_height);
imagecopyresized($dst, $src, 0,0,0,0, $tn_width, $tn_height, $width,
$height);
if($destination!=""){
imagejpeg($dst, $destination, -1);
}else{
return $dst;
}

So if there is no $destination path, it just returns the reference,
what can I do here to return what I need? Is it possible?

Thanks for your help,
Mat
Jul 17 '05 #1
1 5555
I would put that in the "not a very good idea" section....
why would you put your file in the database?
just store the file in a dir on the server and store the path in the DB....
"Mat" <go****@matthewmarlow.com> wrote in message news:84**************************@posting.google.c om...
Hi,
I have a system that uploads images as BLOBs in a database. I also
have a function that I use to resize uploaded images before saving as
files. I would like to combine these two by resising the images before
inserting them as BLOBs.
My problem is that (apart from being new to file stuff) my resize
function returns a Resource ID which of course is not the same as the
file handler that was passed to it, it's a reference to an image
created with imagecreate(). The resize function usually uses
imagejpeg() for the final step of creating the file, is there
something similar I need to use to return a file reference for
inserting into the database?

This is the bit that inserts the resized image into the database..

$thisImage = createImageFromSource($fm_image,"",$imgWidth,$imgH eight,"low");
if($thisImage){
$imageData = addslashes(fread(fopen($thisImage, "r"),
filesize($thisImage)));
doQuery("INSERT into
productImages(fileData,fileSize,fileType,productID )
VALUES('".$imageData."','".$thisImage_size."','".$ thisImage_type."','".$fm_productID."');");
}

As you can see, I need createImageFromSource() to return a file
handler into $thisImage that can be used by the fread and fopen
functions. At present createImageFromSource does this (GD 1.6.2):

$src = imagecreatefromjpeg($source);
$dst = imagecreate($tn_width,$tn_height);
imagecopyresized($dst, $src, 0,0,0,0, $tn_width, $tn_height, $width,
$height);
if($destination!=""){
imagejpeg($dst, $destination, -1);
}else{
return $dst;
}

So if there is no $destination path, it just returns the reference,
what can I do here to return what I need? Is it possible?

Thanks for your help,
Mat

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Matthias Czapla | last post: by
reply views Thread by Andy Jacobs | last post: by
13 posts views Thread by Jon Yeager | last post: by
5 posts views Thread by Jim | last post: by
1 post views Thread by Mike Fellows | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.