Apache-Gallery
view release on metacpan or search on metacpan
lib/Apache/Gallery.pm view on Meta::CPAN
}
if (-f $filename) {
$menu .= $picturename;
}
else {
if ($r->dir_config('GallerySelectionMode') && $r->dir_config('GallerySelectionMode') eq '1') {
$menu .= "<a href=\"".uri_escape($menuurl, $escape_rule);
$menu .= "?select=1\">[select]</a> ";
}
}
return $menu;
}
sub resizepicture {
my ($r, $infile, $outfile, $x, $y, $rotate, $copyrightfile, $GalleryTTFDir, $GalleryCopyrightText, $text_color, $GalleryTTFFile, $GalleryTTFSize, $GalleryCopyrightBackgroundColor, $quality) = @_;
# Load image
my $image = Image::Imlib2->load($infile) or warn("Unable to open file $infile, $!");
# Scale image
$image=$image->create_scaled_image($x, $y) or warn("Unable to scale image $infile. Are you running out of memory?");
# Rotate image
if ($rotate != 0) {
$image->image_orientate($rotate);
}
# blend copyright image onto image
if ($copyrightfile ne '') {
if (-f $copyrightfile and (my $logo=Image::Imlib2->load($copyrightfile))) {
my $x = $image->get_width();
my $y = $image->get_height();
my $logox = $logo->get_width();
my $logoy = $logo->get_height();
$image->blend($logo, 0, 0, 0, $logox, $logoy, $x-$logox, $y-$logoy, $logox, $logoy);
}
else {
log_error("GalleryCopyrightImage $copyrightfile was not found");
}
}
if ($GalleryTTFDir && $GalleryCopyrightText && $GalleryTTFFile && $text_color) {
if (!-d $GalleryTTFDir) {
log_error("GalleryTTFDir $GalleryTTFDir is not a dir\n");
} elsif ($GalleryCopyrightText eq '') {
log_error("GalleryCopyrightText is empty. No text inserted to picture\n");
} elsif (!-e "$GalleryTTFDir/$GalleryTTFFile") {
log_error("GalleryTTFFile $GalleryTTFFile was not found\n");
} else {
$GalleryTTFFile =~ s/\.TTF$//i;
$image->add_font_path("$GalleryTTFDir");
$image->load_font("$GalleryTTFFile/$GalleryTTFSize");
my($text_x, $text_y) = $image->get_text_size("$GalleryCopyrightText");
my $x = $image->get_width();
my $y = $image->get_height();
my $offset = 3;
if (($text_x < $x - $offset) && ($text_y < $y - $offset)) {
if ($GalleryCopyrightBackgroundColor =~ /^\d+,\d+,\d+,\d+$/) {
my ($br_val, $bg_val, $bb_val, $ba_val) = split (/,/, $GalleryCopyrightBackgroundColor);
$image->set_colour($br_val, $bg_val, $bb_val, $ba_val);
$image->fill_rectangle ($x-$text_x-$offset, $y-$text_y-$offset, $text_x, $text_y);
}
my ($r_val, $g_val, $b_val, $a_val) = split (/,/, $text_color);
$image->set_colour($r_val, $g_val, $b_val, $a_val);
$image->draw_text($x-$text_x-$offset, $y-$text_y-$offset, "$GalleryCopyrightText");
} else {
log_error("Text is to big for the picture.\n");
}
}
}
if ($quality && $quality =~ m/^\d+$/) {
$image->set_quality($quality);
}
$image->save($outfile);
}
sub gallerysort {
my $r=shift;
my @files=@_;
my $sortby = $r->dir_config('GallerySortBy');
my $filename=$r->lookup_uri($r->uri)->filename;
$filename=(File::Spec->splitpath($filename))[1] if (-f $filename);
if ($sortby && $sortby =~ m/^(size|atime|mtime|ctime)$/) {
@files = map(/^\d+ (.*)/, sort map(stat("$filename/$_")->$sortby()." $_", @files));
} else {
@files = sort @files;
}
return @files;
}
# Create Text::Template objects used by Apache::Gallery. Takes a
# hashref of template_name, template_filename pairs, and returns a
# list of template_name, texttemplate_object pairs.
sub create_templates {
my $templates = shift;
# This routine is called whenever a template has an error. Prints
# the error to STDERR and sticks the error in the output
sub tt_broken {
my %args = @_;
# Pull out the name and filename from the arg option [see
# Text::Template for details]
@args{qw(name file)} = @{$args{arg}};
print STDERR qq(Template $args{name} ("$args{file}") is broken: $args{error});
# Don't include the file name in the output, as the user can see this.
return qq(<!-- Template $args{name} is broken: $args{error} -->);
}
lib/Apache/Gallery.pm view on Meta::CPAN
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.
( run in 0.805 second using v1.01-cache-2.11-cpan-5735350b133 )