Ok, since I've posted questions about this on a few occasions, I thought I'd be kind, 
and share the solution I have found to creating dynamic thumbnails from images stored 
within a MySQL database. For the sake of brevity, I will only show an example for 

To begin with, add your image to your Database.  I opted to only pretreat my binary 
data with the addslasshes command.

Once your image is in the database, you need to be able to pull it out in a normal 
fashion. The getpic.php script handles this:

if($id) {
    $query = "select image,type from images where id=$id";
    $result = mysql_query($query);
    $data = mysql_result($result,0,"image");
    $type = mysql_result($result,0,"type");
    Header( "Content-type: $type");
    echo $data;

Using getpic.php in conjuction with the <IMG> tag can display the fullsize picture.

Now, to the fun part! Dynamicly creating a thumbnail from the fullsize binary within 
your database. To create the thumbnail, I have a script called mkthumb.php:

          $src = 
          $twidth = imagesx($src)/3;
          $theight = imagesy($src)/3;
          $img = imagecreate($twidth,$theight);

You use mkthump.php in the same exact way that you use getpic.php.  Now, obviously, 
mkthumb.php needs to be modified to handle filetypes other than jpeg. That should be a 
simple task, I just haven't done it yet.... should be as simple as checking the file 
type (I insert the type into a column when I store the original image)

this works.....  if anyone can think of a better way to do anything I have done, feel 
free to add your 2 cents....  I'm certainly open to it.  :)

Jason Bell

Reply via email to