the mySql database. I looked around for code/tutorials and patched a few together to get the following code:
Code: Select all
<?php
#------------------------------------------------------------------
# DATABASE IMAGE THUMBNAILER
#
# Retrieves specified image from mysql database, resizes it, and
# outputs it as an image file.
#------------------------------------------------------------------
#------------------------------------------------------------------
# HEADER
#------------------------------------------------------------------
header("Content-type: image/jpeg");//header
#------------------------------------------------------------------
# DATA FIELDS
#------------------------------------------------------------------
$max_width = 485; // Max Thumbnail width
$max_height = 368; // Max Thumbnail height
$id = $_GET['id']; //Get ID of photo
if($id == null){ $id = 1; } //make sure there is a value for ID
#------------------------------------------------------------------
# MSQL DATABASE
#------------------------------------------------------------------
# connect to database #
include 'mysql_config.php';//include mysql login information
$dbcx = mysql_connect($localhost,$username,$password)
or die("There was an error connecting to your database!<BR>");
@mysql_select_db($image_db,$dbcx)
or die("there was an error selecting the database!<BR>" . mysql_error());
# query database #
$result = mysql_query("SELECT image FROM images WHERE id = $id")
or die("there was an error reading data!<BR>" . mysql_error());
$row=mysql_fetch_object($result);
#------------------------------------------------------------------
# IMAGE PROCESSING
#------------------------------------------------------------------
# create image file from database file #
$srcimage = imagecreatefromjpeg($row->image);
# obtain height & width information #
$width = imageSX($srcimage);
$height = imageSY($srcimage);
$w_h_ratio = $width / $height;//width-to-height ratio
$h_w_ratio= $height / $width;//height-to-width ratio
# determine how large thumbnail should be #
if (($w_h_ratio * $max_height) <= $max_width) {
$new_width = $w_h_ratio * $max_height;
$new_height = $max_height;
} else {
$new_width = $max_width;
$new_height = $h_w_ratio * $max_width;
} //end if/else
# create thumbnail image #
$destimage = imagecreatetruecolor($new_width,$new_height); //create blank truecolor image
imagecopyresized($destimage,$srcimage,0,0,0,0,$new_width,$new_height,$width,$height);
// copy original image into blank image (resized)
ImageJPEG($destimage, '', 100); // display image
ImageDestroy($destimage);
?>any ideas????
i realize that it might be easier to just store the images on the server and put file paths in the db, but thats not any fun nw is it?