Hmmmm,
This board feels like a big empty room! I'll throw my question out there anyway.
I have some images which are resized and outputted from a database, which is no problem, I have the system down for creating the image and outputting it to a browser. What I want to know is this: can I call on an image through GD functions without first outputting it through another script.
Example of the kinda thing I mean:
I have an image stored here in the public_profiles table that I want to resize down to a thumbnail. So far I have had to call on an external script to output that image with image headers before I can run it through the resize functions. Seems to me that I am doing more work than I have to, if I can just pull the image from the table here and use it directly it would be more efficient.
//snip snip
/* query file_type for headers */
$image_query = mysql_query("SELECT file_type FROM public_profiles WHERE user_id = '{$_REQUEST["user"]}'");
$image_data = mysql_fetch_array($image_query);
/* call on external script to output the complete image for resize functions from the same database table */
$source_file = "http://www.smilingsouls.net/images/profile_image.php?user={$_REQUEST["user"]}";
$size = getimagesize($source_file);
$maximum_width = 75;
$maximum_height = 75;
$width = $size[0];
$height = $size[1];
$x_ratio = $maximum_width / $width;
$y_ratio = $maximum_height / $height;
if (($width <= $maximum_width) && ($height <= $maximum_height)) {
$picture_width = $width;
$picture_height = $height;
} else if (($x_ratio * $height) < $maximum_height) {
$picture_height = ceil($x_ratio * $height);
$picture_width = $maximum_width;
} else {
$picture_width = ceil($y_ratio * $width);
$picture_height = $maximum_height;
}
/* find the file_type of the image and resize accordingly */
if ($image_data["file_type"] == "image/jpeg" || $image_data["file_type"] == "image/pjpeg" || $image_data["file_type"] == "image/jpg") {
/* make another freaking jpeg! */
$source_file = imagecreatefromjpeg($source_file);
/* make empty jpeg with resized dimensions in ratio to the old */
$destination_file = imagecreatetruecolor($picture_width, $picture_height);
/* merge the two */
imagecopyresized($destination_file, $source_file, 0, 0, 0, 0, $picture_width, $picture_height, $width,$height);
header("Content-type: image/pjpeg");
/* output the resized image to be called on by img src */
imagejpeg($destination_file, null, -1);
/* clean up the cache */
imagedestroy($source_file);
imagedestroy($destination_file);
}
So if I could find a way to make the source file not refer to the external url I think I'd have this thing licked! Maybe a function that I have not yet found?
Sorry about all the code, I hope it isn't too messy! I can't really think of a good way to format it in this little textarea box.
Thanks!
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::