mhearse has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I've been storing satellite weather images into a MySQL database. Now I'd like to animate them on a webpage. I want to animate 50 to 100 images at a time (maybe more later). They are small 90k jpegs, and would be accessed mainly over a LAN. Javascript seems to work, as far as animating images in the working directory (I'm open to other suggestions). My question: what's the best way to make the images available for animation (to the web server in this case)? It seems wasteful to grab images and store them in a temporary directory (which is all I've tried so far). Could this be done via CGI? Once the DBI script stores the images in a data structure, what would come next? Any input is appreciated.

Replies are listed 'Best First'.
Re: Animating images from database
by BUU (Prior) on Jan 21, 2005 at 05:00 UTC
    #!/usr/bin/perl use CGI; #Hate this use DBI; print "Content-type: image/jpeg\n\n"; binmode STDOUT; #win32; my $dbh = DBI->connect("relevant stuff here"); my $image_date; my $sth = $dbh->prepare("SELECT data FROM images WHERE id=?"); $sth->execute( param('img') ); $sth->bind_column( \$image_data ); #erm. I think $sth->fetch; $sth->finish; $dbh->disconnect; print $image_data; #done

      I think that if you're not going to use the OO interface to CGI, you have to specify "use CGI qw( :standard ); for the param() subroutine to be exported (and thus available to your main script).


      Dave

Re: Animating images from database
by inman (Curate) on Jan 21, 2005 at 09:28 UTC
    Slightly different take on the problem - if you want to publish an animation of the last 24 hours weather then convert your JPGs into a an animated GIF (using imagemagick or similar). This is the way that I have seen it done on public meteorology sites.

    Checkout the convert method. It looks like you will be able to convert a number of jpegs to gifs and animate them.

Re: Animating images from database
by TedPride (Priest) on Jan 21, 2005 at 10:00 UTC
    Some background info might be useful. Why are the images being stored in a database? Do you need to be able to access images farther back than the 50-100 images needed for animation? Are those 50-100 images always going to be the most recent ones? What's the expected number of views? I'd personally store the images in folders by day using some naming system involving timestamps, thus making it unnecessary to use a database to access the images.
      Whether to store images in a database or not has been much talked about on the MySQL lists. The general consensus seems to be that you should store the image files in a filesystem since that's what a filesystem is designed for and store the html links to the images in a database since they're data for your program and that's what a database is for.

      Jack

        database systems would be faster than a file system at reading in image data for small images in quick succession. reason is that the db can read ahead in blocks, and will be working from maybe a couple of file system files. if you open/read/close 100 images from a file system, that's approx 100 seek operations on the disk, besides the 100 open/close OS overheads. And since you also store the image metadata (e.g. timestamp etc.) in the same db table, retrieving the right 100 images is a single sql statement. storing same images with timestamped directories/files or whatever concocted method, means that you have to write silly code just to get the right image filenames/files. i think that all that the thread poster wanted was a method for displaying the images from the database through a webserver. i believe that "multi-part" html page will do that, you just keep printing the next jpeg. the exact method/code is described in the book "Programming Web graphics with Perl and GNU software".
        the hardest line to type correctly is: stty erase ^H
Re: Animating images from database
by g0n (Priest) on Jan 21, 2005 at 12:39 UTC