waygood
asked on
Get image data pointed to by a Resource id
I am currently working on a gallery project.
I have written code to store clients photos in a Mysql database, which is all working okay. I want to create a thumbnail on the fly which I do with the following code :-
$def_thumb_width=100;
$def_thumb_height=75;
$thumb_image_name= "t_" . $original_image_name;
$scaling_width=$original_i mage_width / $def_thumb_width;
$scaling_height=$original_ image_heig ht / $def_thumb_height;
if ($scaling_width > $scaling_height)
{
$thumb_width=$original_ima ge_width / $scaling_width;
$thumb_height=$original_im age_height / $scaling_width;
}
else
{
$thumb_width=$original_ima ge_width / $scaling_height;
$thumb_height=$original_im age_height / $scaling_height;
}
$thumb_width= ceil($thumb_width);
$thumb_height= ceil($thumb_height);
$im=imagecreatefromjpeg("$ original_i mage");
$thumb=imagecreate($thumb_ width,$thu mb_height) ;
imagecopyresized($thumb,$i m,0,0,0,0, $thumb_wid th,$thumb_ height,$or iginal_ima ge_width,$ original_i mage_heigh t)
I have used fopen to open the original file in order to get the binary for the file. To prevent writing the data out to a file and reading it back again, I need to gain access to the data. $thumb will contain the image resource, and ImageJPEG($thumb) will output the data to the screen but I want it sent to my database instead.
In short how do I access data pointed to by a resource id.
I have written code to store clients photos in a Mysql database, which is all working okay. I want to create a thumbnail on the fly which I do with the following code :-
$def_thumb_width=100;
$def_thumb_height=75;
$thumb_image_name= "t_" . $original_image_name;
$scaling_width=$original_i
$scaling_height=$original_
if ($scaling_width > $scaling_height)
{
$thumb_width=$original_ima
$thumb_height=$original_im
}
else
{
$thumb_width=$original_ima
$thumb_height=$original_im
}
$thumb_width= ceil($thumb_width);
$thumb_height= ceil($thumb_height);
$im=imagecreatefromjpeg("$
$thumb=imagecreate($thumb_
imagecopyresized($thumb,$i
I have used fopen to open the original file in order to get the binary for the file. To prevent writing the data out to a file and reading it back again, I need to gain access to the data. $thumb will contain the image resource, and ImageJPEG($thumb) will output the data to the screen but I want it sent to my database instead.
In short how do I access data pointed to by a resource id.
ASKER
I did capure the data as a work around using :-
ob_start();
Imagejpeg($thumb);
$thumb_image_size=ob_get_l ength();
$thumb_data=addslashes(ob_ get_conten ts());
ob_end_clean();
but fail to see why I need to output data and recapture it again through buffering of saving as a file. The data is there, I just need to access it.
P.S. I am writing this for people who are very stupid. They don't know how to deal with more than one program open at a time, let alone how to create thumbnails. I gave them Mihov's Image Resizer (freeware) and they complained when it doubled the number of images they had (extra thumbnails). Duh!
ob_start();
Imagejpeg($thumb);
$thumb_image_size=ob_get_l
$thumb_data=addslashes(ob_
ob_end_clean();
but fail to see why I need to output data and recapture it again through buffering of saving as a file. The data is there, I just need to access it.
P.S. I am writing this for people who are very stupid. They don't know how to deal with more than one program open at a time, let alone how to create thumbnails. I gave them Mihov's Image Resizer (freeware) and they complained when it doubled the number of images they had (extra thumbnails). Duh!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I use a program called ThumbsPlus on Windows. It can write to MySQL databases no problems.
But to answer your question, you can add a file name to
ImageJPEG($thumb,"/home/im
and then put that file in the database the same way you did the main image.
I cannot see a standard function to allow you to access the data directly.
BUT, what would happen if you sent the data to STDOUT (or something similar) and caught it via another program/script? No idea if possible.
Regards,
Richard Quadling.