Apache-Gallery
view release on metacpan or search on metacpan
lib/Apache/Gallery.pm view on Meta::CPAN
$filename =~ s/\.cache//;
$filename =~ m/\/(\d+)x(\d+)\-/;
my $image_width = $1;
my $image_height = $2;
$filename =~ s/\/(\d+)x(\d+)\-//;
my ($width, $height, $type) = imgsize($filename);
my $imageinfo = get_imageinfo($r, $filename, $type, $width, $height);
my $cached = scale_picture($r, $filename, $image_width, $image_height, $imageinfo);
my $file = cache_dir($r, 0);
$file =~ s/\.cache//;
my $subr = $r->lookup_file($file);
$r->content_type($subr->content_type());
if ($::MP2) {
my $fileinfo = stat($file);
my $nonce = md5_base64($fileinfo->ino.$fileinfo->mtime);
if ($r->headers_in->{"If-None-Match"} eq $nonce) {
return Apache2::Const::HTTP_NOT_MODIFIED();
}
if ($r->headers_in->{"If-Modified-Since"} && str2time($r->headers_in->{"If-Modified-Since"}) < $fileinfo->mtime) {
return Apache2::Const::HTTP_NOT_MODIFIED();
}
$r->headers_out->{"Content-Length"} = $fileinfo->size;
$r->headers_out->{"Last-Modified-Date"} = time2str($fileinfo->mtime);
$r->headers_out->{"ETag"} = $nonce;
$r->sendfile($file);
return Apache2::Const::OK();
}
else {
$r->path_info('');
$r->filename($file);
return Apache::Constants::DECLINED();
}
}
my $uri = $r->uri;
$uri =~ s/\/$//;
unless (-f $filename or -d $filename) {
show_error($r, 404, "404!", "No such file or directory: ".uri_escape($r->uri, $escape_rule));
return $::MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
}
my $doc_pattern = $r->dir_config('GalleryDocFile');
unless ($doc_pattern) {
$doc_pattern = '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|ogg|pdf|rtf|wav|dlt|txt|html?|csv|eps)$'
}
my $img_pattern = $r->dir_config('GalleryImgFile');
unless ($img_pattern) {
$img_pattern = '\.(jpe?g|png|tiff?|ppm)$'
}
# Let Apache serve files we don't know how to handle anyway
if (-f $filename && $filename !~ m/$img_pattern/i) {
return $::MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
}
if (-d $filename) {
unless (-d cache_dir($r, 0)) {
unless (create_cache($r, cache_dir($r, 0))) {
return $::MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
}
}
my $tpl_dir = $r->dir_config('GalleryTemplateDir');
# Instead of reading the templates every single time
# we need them, create a hash of template names and
# the associated Text::Template objects.
my %templates = create_templates({layout => "$tpl_dir/layout.tpl",
index => "$tpl_dir/index.tpl",
directory => "$tpl_dir/directory.tpl",
picture => "$tpl_dir/picture.tpl",
file => "$tpl_dir/file.tpl",
comment => "$tpl_dir/dircomment.tpl",
nocomment => "$tpl_dir/nodircomment.tpl",
rss => "$tpl_dir/rss.tpl",
rss_item => "$tpl_dir/rss_item.tpl",
navdirectory => "$tpl_dir/navdirectory.tpl",
});
my %tpl_vars;
$tpl_vars{TITLE} = "Index of: $uri";
if ($media_rss_enabled) {
# Put the RSS feed on all directory listings
$tpl_vars{META} = '<link rel="alternate" href="?rss=1" type="application/rss+xml" title="" id="gallery" />';
}
unless (opendir (DIR, $filename)) {
show_error ($r, 500, $!, "Unable to access directory $filename: $!");
return $::MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
}
$tpl_vars{MENU} = generate_menu($r);
$tpl_vars{FORM_BEGIN} = $select_mode?'<form method="post">':'';
$tpl_vars{FORM_END} = $select_mode?'<input type="submit" name="Get list" value="Get list"></form>':'';
# Read, sort, and filter files
my @files = grep { !/^\./ && -f "$filename/$_" } readdir (DIR);
@files=gallerysort($r, @files);
my @downloadable_files;
lib/Apache/Gallery.pm view on Meta::CPAN
'Orientation' EXIF field. Apache::Gallery will then automatically
rotate your images.
This behavior is default but can be disabled by setting GalleryAutoRotate
to 0.
=item B<GalleryCacheDir>
Directory where Apache::Gallery should create its cache with scaled
pictures. The default is /var/cache/www/ . Here, a directory for each
virtualhost or location will be created automatically. Make sure your
webserver has write access to the CacheDir.
=item B<GalleryTemplateDir>
Full path to the directory where you placed the templates. This option
can be used both in your global configuration and in .htaccess files,
this way you can have different layouts in different parts of your
gallery.
No default value, this option is required.
=item B<GalleryInfo>
With this option you can define which EXIF information you would like
to present from the image. The format is: '<MyName => KeyInEXIF,
MyOtherName => OtherKeyInEXIF'
Examples of keys: B<ShutterSpeedValue>, B<ApertureValue>, B<SubjectDistance>,
and B<Camera>
You can view all the keys from the EXIF header using this perl-oneliner:
perl C<-e> 'use Data::Dumper; use Image::Info qw(image_info); print Dumper(image_info(shift));' filename.jpg
Default is: 'Picture Taken => DateTimeOriginal, Flash => Flash'
=item B<GallerySizes>
Defines which widths images can be scaled to. Images cannot be
scaled to other widths than the ones you define with this option.
The default is '640 800 1024 1600'
=item B<GalleryThumbnailSize>
Defines the width and height of the thumbnail images.
Defaults to '100x75'
=item B<GalleryThumbnailSizeLS>
If set to '1', B<GalleryThumbnailSize> is the long and the short side of
the thumbnail image instead of the width and height.
Defaults to '0'.
=item B<GalleryCopyrightImage>
Image you want to blend into your images in the lower right
corner. This could be a transparent png saying "copyright
my name 2001".
Optional.
=item B<GalleryWrapNavigation>
Make the navigation in the picture view wrap around (So Next
at the end displays the first picture, etc.)
Set to 1 or 0, default is 0
=item B<GalleryAllowOriginal>
Allow the user to download the Original picture without
resizing or putting the CopyrightImage on it.
Set to 1 or 0, default is 0
=item B<GallerySlideshowIntervals>
With this option you can configure which intervals can be selected for
a slideshow. The default is '3 5 10 15 30'
=item B<GallerySortBy>
Instead of the default filename ordering you can sort by any
stat attribute. For example size, atime, mtime, ctime.
=item B<GalleryDirSortBy>
Set this variable to sort directories differently than other items,
can be set to size, atime, mtime and ctime; setting any other value
will revert to sorting by name.
=item B<GalleryMemoize>
Cache EXIF data using Memoize - this will make Apache::Gallery faster
when many people access the same images, but it will also cache EXIF
data until the current Apache child dies.
=item B<GalleryUseFileDate>
Set this option to 1 to make A::G show the files timestamp
instead of the EXIF value for "Picture taken".
=item B<GallerySelectionMode>
Enable the selection mode. Select images with checkboxes and
get a list of filenames.
=item B<GalleryEXIFMode>
You can choose how Apache::Gallery should display EXIF info
from your images.
The default setting is 'namevalue'. This setting will make
Apache::Gallery print out the names and values of the EXIF values
you configure with GalleryInfo. The information will be parsed into
$INFO in pictureinfo.tpl.
You can also set it to 'values' which will make A::G parse
the configured values into the var $EXIFVALUES as 'value | value | value'
If you set this option to 'variables' the items you configure in GalleryInfo
will be available to your templates as $EXIF_<KEYNAME> (in all uppercase).
That means that with the default setting "Picture Taken => DateTimeOriginal,
Flash => Flash" you will have the variables $EXIF_DATETIMEORIGINAL and
$EXIF_FLASH available to your templates. You can place them
anywhere you want.
=item B<GalleryRootPath>
Change the location of gallery root. The default is ""
=item B<GalleryRootText>
Change the name that appears as the root element in the menu. The
default is "root:"
=item B<GalleryMaxThumbnailsPerPage>
This options controls how many thumbnails should be displayed in a
page. It requires $BROWSELINKS to be in the index.tpl template file.
=item B<GalleryImgFile>
Pattern matching the files you want Apache::Gallery to view in the
index as thumbnails.
The default is '\.(jpe?g|png|tiff?|ppm)$'
=item B<GalleryDocFile>
Pattern matching the files you want Apache::Gallery to view in the index
as normal files. All other filetypes will still be served by Apache::Gallery
but are not visible in the index.
The default is '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|ogg|pdf|rtf|wav|dlt|txt|html?|csv|eps)$'
=item B<GalleryTTFDir>
To use the GalleryCopyrightText feature you must set this option to the
directory where your True Type fonts are stored. No default is set.
Example:
PerlSetVar GalleryTTFDir '/usr/share/fonts/'
=item B<GalleryTTFFile>
To use the GalleryCopyrightText feature this option must be set to the
name of the True Type font you wish to use. Example:
PerlSetVar GalleryTTFFile 'verdanab.ttf'
=item B<GalleryTTFSize>
Configure the size of the CopyrightText that will be inserted as
copyright notice in the corner of your pictures.
Example:
PerlSetVar GalleryTTFSize '10'
=item B<GalleryCopyrightText>
The text that will be inserted as copyright notice.
Example:
PerlSetVar GalleryCopyrightText '(c) Michael Legart'
=item B<GalleryCopyrightColor>
The text color of your copyright notice.
Examples:
White:
PerlSetVar GalleryCopyrightColor '255,255,255,255'
Black:
PerlSetVar GalleryCopyrightColor '0,0,0,255'
Red:
PerlSetVar GalleryCopyrightColor '255,0,0,255'
Green:
PerlSetVar GalleryCopyrightColor '0,255,0,255'
Blue:
PerlSetVar GalleryCopyrightColor '0,0,255,255'
Transparent orange:
PerlSetVar GalleryCopyrightColor '255,127,0,127'
=item B<GalleryCopyrightBackgroundColor>
The background-color of a GalleryCopyrightText
r,g,b,a - for examples, see GalleryCopyrightColor
=item B<GalleryQuality>
The quality (1-100) of scaled images
This setting affects the quality of the scaled images.
Set this to a low number to reduce the size of the scaled images.
Remember to clear out your cache if you change this setting.
Quality seems to default to 75, at least in the jpeg and png loader code in
Imlib2 1.1.0.
Examples:
Quality at 50:
PerlSetVar GalleryQuality '50'
=item B<GalleryUnderscoresToSpaces>
Set this option to 1 to convert underscores to spaces in the listing
of directory and file names, as well as in the alt attribute for HTML
<img> tags.
=back
=over 4
=item B<GalleryCommentExifKey>
Set this option to e.g. ImageDescription to use this field as comments
for images.
=item B<GalleryEnableMediaRss>
Set this option to 1 to enable generation of a media RSS feed. This
can be used e.g. together with the PicLens plugin from http://piclens.com
=back
=head1 FEATURES
=over 4
=item B<Rotate images>
Some cameras, like the Canon G3, detects the orientation of a picture
and adds this info to the EXIF header. Apache::Gallery detects this
and automatically rotates images with this info.
If your camera does not support this, you can rotate the images
manually, This can also be used to override the rotate information
from a camera that supports that. You can also disable this behavior
with the GalleryAutoRotate option.
To use this functionality you have to create file with the name of the
picture you want rotated appended with ".rotate". The file should include
a number where these numbers are supported:
"1", rotates clockwise by 90 degree
"2", rotates clockwise by 180 degrees
"3", rotates clockwise by 270 degrees
So if we want to rotate "Picture1234.jpg" 90 degrees clockwise we would
create a file in the same directory called "Picture1234.jpg.rotate" with
the number 1 inside of it.
=item B<Ignore directories/files>
To ignore a directory or a file (of any kind, not only images) you
create a <directory|file>.ignore file.
( run in 2.108 seconds using v1.01-cache-2.11-cpan-df04353d9ac )