| Image-Shoehorn-Gallery documentation | view source | Contained in the Image-Shoehorn-Gallery distribution. |
Image::Shoehorn::Gallery - generate "smart" HTML slideshows from a directory of image files.
use Image::Shoehorn::Gallery;
Image::Shoehorn::Gallery->create({
source => "~/my-images",
directory => "/htdocs/images",
url => "http://mysite.com/images",
static => 1,
scales => [
[ "thumb","75x50" ],
[ "default", "50%" ],
[ "small","25%" ],
[ "medium","50%" ],
],
scale_if => { x => 400 , y => 300 },
iptc => ["headline","caption/abstract"],
set_lang => "en-ca",
set_styles => {
image => [
{title=>"my css",href=>"/styles.css"},
],
},
set_index_images => { default => 1 },
});
Image::Shoehorn::Gallery generates HTML slideshows from a directory of image files. But wait, there's more!
Image::Shoehorn uses XML::Filter::XML_Directory_2XHTML, XML::SAX::Machines and a small army of Image::* packages allowing you to :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version = "1.0" >
<xsl:template match = "/"> <html> <xsl:copy-of select = "html/head" /> <body>
<!-- lots of foofy design stuff -->
<xsl:copy-of select = "/html/body/*" />
<!-- lots of foofy design stuff -->
</body> </html> </xsl:template>
</xsl:stylesheet>
This is the magic spell that will create your galleries.
Valid arguments are :
package MySAX; use base qw (XML::SAX::Base);
sub start_element {
my $self = shift;
my $data = shift;
$self->SUPER::start_element($data);
if ($data->{Name} eq "body") {
$self->SUPER::start_element({Name=>"h1"});
$self->SUPER::characters({Data=>"hello world"});
$self->SUPER::end_element({Name=>"h1"});
}
}
package main;
# The following will add <h1>hello world</h1> # at the top of all your 'image' pages. Woot!
use Image::Shoehorn::Gallery;
Image::Shoehorn::Gallery->create({
# ...
set_filters => { image => [ MySAX->new() ]},
});
# Use the default Apache icons
my %images = (
directory => {
src => "/icons/dir.gif",
height => "20",
width => "20",
alt => "ceci n'est pas un dossier",
},
file => {
src => "/icons/unknown.gif",
height => "20",
width => "20",
alt => "ceci n'est pas un fichier",
},
);
Image::Shoehorn::Gallery->create({
# ...
set_index_images => \%images,
});
Let's say you've got an image named :
20020603-my-new-toy.jpg
You've defined two "views" to be generated : small and medium. The following files will be created :
20020603-my-new-toy.html
20020603-my-new-toy-thumb.jpg **
20020603-my-new-toy-small.jpg *
20020603-my-new-toy-small.html
20020603-my-new-toy-medium.jpg *
20020603-my-new-toy-medium.html
* If you are rendering scaled images on the fly, with I<Apache::Image::Shoehorn>,
these files not be created until such a time as they are actually viewed
** Thumbnails are always generated, regardless of the I<static> flag. As mentioned
earlier, this is a feature. If you have a directory with many images, you will peg
your web server the first time you have to render all those images for the index
listing.
The package uses XML::Filter::XML_Directory_2XHTML which, a few steps up the inheritance tree, uses XML::Filter::XML_Directory_Pruner to exclude certain specific files from the directory (index) listing. The exact rule set currently used it :
$xhtml->exclude(
starting => ["\\."],
ending => ["html","tmp","~"],
# e.g. ending with "-thumb.jpg","-small.jpg" or "-medium.jpg"
matching => ["^(.*)-(".join("|","thumb",@{$views}).")\.([^\.]+)\$"],
);
The plan is to, eventually, teach XML::Filter::XML_Directory_Pruner to include and exclude widgets based on media type, at which point we could simply do :
$xhtml->include( media => "image" );
But until then, it is recommended that you make sure your source images don't match the "matching" pattern describe above. Or if you just think I'm an idiot and have a better rule-set, send my a note and I'll probably include it.
The following CSS classes are defined for the HTML generated by the package.
They are provided as a reference in case you want to specify your own CSS stylesheet.
body {
background-color: #ffffff;
margin:0;
}
.breadcrumbs {
display:block;
background-color: #f5f5dc;
padding:5px;
margin-bottom:5px;
border-bottom: solid thin;
}
.breadcrumbs-spacer {}
.directory { margin-bottom:5px;clear:left; padding: 5px;}
.file { margin-bottom:5px;clear:left;padding: 5px;}
.thumbnail { display:block;width:100px;float:left;}
.file ul { float:left;}
body {
background-color: #ffffff;
margin:0;
}
.breadcrumbs {
display:block;
background-color: #f5f5dc;
padding:5px;
margin-bottom:5px;
border-bottom: solid thin;
}
.breadcrumbs-spacer {}
.directory {
padding: 5px;
}
.file {
padding: 5px;
}
.menu {
margin-bottom:5px;
padding:5px;
}
.menu-link-previous {
padding-right : 10px;
}
.menu-link-previous img {
margin-right:15px;
}
.menu-link-index {
font-weight:600;
}
.menu-link-next {
padding-left : 10px;
}
.menu-link-next img {
margin-left:15px;
}
.content {
padding-top:20px;
}
.image {
position:absolute;
top:auto;
right:auto;
left:170px;
bottom:auto;
}
.meta {
min-width:150px;
max-width:150px;
margin:5px;
}
.links {
border: solid thin;
margin-bottom: 5px;
}
.links span {
display:block;
padding:3px;
}
.iptc {
background-color : #fffff0;
border-top: solid thin;
border-left: solid thin;
border-right: solid thin;
margin-bottom : 5px;
}
.iptc span {
display:block;
padding:3px;
border-bottom:solid thin;
}
.iptc-field {
background-color : #f5f5dc;
color:#a52a2a;
border-bottom:solid thin #000;
}
.exif {
background-color : #f5f5dc;
border-top: solid thin;
border-left: solid thin;
border-right: solid thin;
margin-bottom : 5px;
}
.exif span {
display:block;
padding:3px;
border-bottom:solid thin;
}
.exif-field {
color:#a52a2a;
background-color:#cccc99;
border-bottom:solid thin #000;
}
0.22
Aaron Straup Cope
September 02, 2002
http://aaronland.net/weblog/archive/3940
http://aaronland.net/weblog/archive/4474
http://www.la-grange.net/2002/07/22.html
http://perl.aaronland.info/image/shoehorn/gallery/www/example/index.html
XML::Filter::XML_Directory_2XHTML
XML::Filter::XSLT
XML::SAX::Machines
XML::SAX::Writer
Image::Shoehorn
Image::IPTCInfo
Image::Info
Digest::MD5
Undoubtedly. So far, it works for me.
Copyright (c) 2002, Aaron Straup Cope. All Rights Reserved.
This is free software, you may use it and distribute it under the same terms as Perl itself.
| Image-Shoehorn-Gallery documentation | view source | Contained in the Image-Shoehorn-Gallery distribution. |