Welcome to the Monastery. The task you are attempting is not a trivial one, but, if you are willing to give it a try, you will find that Perl is a great tool for the job.

You need to look at the job in front of you in terms of input and output. Your input seems to be the name of a directory. Given the directory name, you want to write a script that will look into the directory, get the names of the image files, and the description from the text file, and produce an html file with the gallery - your desired output. Since you probably want to produced galleries with consistent look, you need to look at some templating tools to make your job easier. I would recommend HTML::Template.

Start with creating a basic template file, gallery.tmpl.

<html> <head> <style> div.img { margin: 5px; padding: 5px; border: 1px solid #0000ff; height: auto; width: auto; float: left; text-align: center; } div.img img { display: inline; margin: 5px; border: 1px solid #ffffff; } div.img a:hover img { border:1px solid #0000ff; } </style> </head> <body> <p> <TMPL_VAR NAME=DESCR> </p> <TMPL_LOOP NAME=GALLERY> <div class="img"> <a target="_blank" href="<TMPL_VAR NAME=IMG_BIG>"> <img src="<TMPL_VAR NAME=IMG_SMALL>" width="110" height="90"> </a> </div> </TMPL_LOOP> </body> </html>

It contains one description field, and a loop that will create appropriate div blocks for every image.

Try it out with the following code.

#!/usr/bin/perl use v5.14; use HTML::Template; my $template = HTML::Template->new(filename => 'gallery.tmpl'); my @gallery; for my $count (1..3) { my %data = ( img_small => "img$count-small.jpg", img_big => "img$count-big.jpg", ); push @gallery, \%data; } $template->param(DESCR => "Some general description"); $template->param(GALLERY => \@gallery); print $template->output;

If the names of the images in your directory happen to be 1-small.jpg, 1-big.jpg, and so on, and you are satisfied with the predefined string "Some general description" as your description, this could be what you want. But it probably isn't. Right now, we're producing the output, but we're ignoring the input completely.

The next step would be to read the description from a file. Take a look at the File::Slurp module, and use it to read a plain text file in a given directory. Then, substitute the DESCR param with the description gathered from your file (the file contents). Then, take a look at Find all JPEG files in a directory, and expand the script a bit more. Then, your job will hopefully be finished.

Good luck.

- Luke


In reply to Re: Need some direction by blindluke
in thread Need some direction by barelahh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.