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

Greetings fellow monks,

Last week we returned from a short vacation in Vieques, Puerto Rico, and of course had plenty of digital pictures to sort through.  I had toyed before with writing a short Perl program to categorize digital photos; something that would let me rotate and/or resize photos needing editing, choose which photos to delete or save for the final presentation, and ultimately create an HTML page for viewing them.

Now, let me say up front, that I'm aware there must be dozens of such programs available, and probably quite a few good freeware versions as well.  But in my case, it's not just the fun of writing my own, there's also the learning experience which I enjoy, and the flexibility of having it do *exactly* what I want it to.

So, in designing such a program, an obvious approach which came to mind is to use Image::Magick to create the initial thumbnails, and write an HTML page to render the thumbnail images for quick viewing by a favorite browser (ie. Firefox).  Browsers are, of course, optimized for speed in displaying images, so it seems only natural to make use of HTML for the initial presentation for selecting editing operations.

However, this is where I run into problems ... I can't figure out how to communicate from the HTML page back to the Perl program (or even a separate Perl program), in order to process those images which the user selects.  I searched for and found information on writing files from Javascript, but of course Javascript was not designed for doing this natively (in the client/server model under which a webpage usual operates, it would be a huge security hole to allow Javascript to do any kind of file-processing), so the only way I can of making such an approach work would involve Active-X, and thus Internet Explorer, which I am unwilling to restrict myself to.  Another solution might be to run Apache and make use of CGI scripting, but that seems like a lot of extra work just to make Perl interface with the HTML page.

I even tried a quick test to see how feasible it would be to use Tk, and, as suspected, even trying to load just a small number of photos takes an inordinate amount of time.

So, can someone kindly tell me, what is the standard way to do something like this from Perl?


@ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
  • Comment on Using Perl as a front-end and a back-end to HTML -- is it possible?

Replies are listed 'Best First'.
Re: Using Perl as a front-end and a back-end to HTML -- is it possible?
by zentara (Cardinal) on Mar 19, 2006 at 17:25 UTC
    From what I can gather from your post, running Perl cgi is what you are after, if you want to communicate between a browser and Perl. But I don't understand EXACTLY what sort of program you are trying to create. Do you want to be able to use a browser, and go into a directory of untouched images, select from those images, to make a custom html page which shows your selections as thumbnails? Or do you want a local Tk program, which will allow you to select from a group of images to make an html page?

    I just recently posted a Tk example, to preview images with thumbnails at Tk-thumbnail-viewer, and you could modify that, so that when you click the main image, it would copy it to a "Selected Directory", along with it's thumbnail. Then once your selections are done, you could make a sub to make a custom html page, from everything, in the selected-dir, thumbnails on the left, main images on the right. You could even automatically upload it to your web-server with lwp. Here is a simple framed html page generator, which you could run in your selected dir.

    A local Tk program will be faster than a browser-based solution, because your server will not give you as much cpu time as your local machine will.

    I'm not really a human, but I play one on earth. flash japh
Re: Using Perl as a front-end and a back-end to HTML -- is it possible?
by NetWallah (Canon) on Mar 19, 2006 at 18:26 UTC
    How about incorporating something like HTTP::Server::Simple into your program. You can then create the HTML (possibly on-the-fly), and create a URL to point back into your app, and directly receive info via HTML form based interaction. Your app then reacts to these instructions, and re-renders the HTML. (basically, your app becomes a single-purpose web server).

         "For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken

      Thanks, NetWallah, this looks very promising. ++

      I just installed HTTP::Server::Simple with ppm, and I'm looking into using it now.  There isn't apparently a lot of documentation containing actual examples, so I'll need to experiment a bit.  But it's exactly the kind of thing I was searching for.

      Update:  Perhaps I wasn't clear in my original post, but I'm running this on a single machine, so going with a client/server model (eg. running a full-scale webserver to process the page) isn't what I was after.  I realize that http is not the way to go for processing images, but I'm only intending to use it to select images for editing.  That's where the Perl back-end would come in.

      Update 2:  After fussing with HTTP::Server::Simple, I've gotta say, it ain't so Simple.  :(  However, I did come across this excellent node, written by Corion.  I'm studying it now, with the hopes of incorporating some of it into my own program, but I'm already impressed with how quickly I could get it working on my pc.  :)


      @ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
        You are correct - I had not actually attempted to use the HTTP::Server::Simple module until after your note - and the documentation is very sparse, although it does work, you do need to subclass it, to get anything useful. I apologise for misleading you - what I saw in the minimal documentation made it look appealing.

        If you get into trouble with Corion's 100-liner, you can try the better documented HTTP::Daemon, which documents code for a minimal web server.

        Your original post WAS clear enough - I just liked the idea of a ready-made (browser) client, and a simple, fast web server for your problem space.

             "For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken

Re: Using Perl as a front-end and a back-end to HTML -- is it possible?
by jdporter (Paladin) on Mar 19, 2006 at 17:06 UTC

    Heavy-duty image processing is not what web (i.e. http) was designed for. But that's not to say it couldn't be done. You could show a checkbox by each image, and somewhere on the page (probably the top) have a menu of functions to be applied to the selected images. There could be a couple text inputs as well, for those functions which require parameters. File renaming, if necessary, and such things, could be "smart", done by the server program (your cgi) with little or no input from the user.

    We're building the house of the future together.
Re: Using Perl as a front-end and a back-end to HTML -- is it possible?
by rinceWind (Monsignor) on Mar 19, 2006 at 18:11 UTC

    You might want to look at Apache::ImageMagick, which should do what you want, provided you have a mod-perl enabled Apache.

    You then specify what you want in the URL.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)