By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,640 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,640 IT Pros & Developers. It's quick & easy.

Resizing uploaded images before inserting as BLOB

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.