* Add an img plugin, based on Christian Mock's img plugin, but stripped
down to the bare essentials. Useful for handling large images on websites.master
parent
7b76cce96c
commit
e54d901565
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/perl
|
||||
# Ikiwiki enhanced image handling plugin
|
||||
# Christian Mock cm@tahina.priv.at 20061002
|
||||
package IkiWiki::Plugin::img;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use IkiWiki;
|
||||
use Image::Magick;
|
||||
|
||||
my $convert = 'convert';
|
||||
|
||||
my %imgdefaults;
|
||||
|
||||
sub import { #{{{
|
||||
hook(type => "preprocess", id => "img", call => \&preprocess);
|
||||
} #}}}
|
||||
|
||||
sub preprocess (@) { #{{{
|
||||
my ($image) = $_[0] =~ /$config{wiki_file_regexp}/; # untaint
|
||||
my %params=@_;
|
||||
|
||||
if (! exists $imgdefaults{$params{page}}) {
|
||||
$imgdefaults{$params{page}} = {};
|
||||
}
|
||||
my $size = $params{size} || $imgdefaults{$params{page}}->{size} || 'full';
|
||||
my $alt = $params{alt} || $imgdefaults{$params{page}}->{alt} || '';
|
||||
|
||||
if ($image eq 'defaults') {
|
||||
$imgdefaults{$params{page}} = {
|
||||
size => $size,
|
||||
alt => $alt,
|
||||
};
|
||||
return '';
|
||||
}
|
||||
|
||||
my $file = bestlink($params{page}, $image) || return "[[img $image not found]]";
|
||||
add_depends($params{page}, $file);
|
||||
|
||||
my $dir = IkiWiki::dirname($file);
|
||||
my $base = IkiWiki::basename($file);
|
||||
my $im = Image::Magick->new;
|
||||
my $imglink;
|
||||
my $r;
|
||||
|
||||
if ($size ne 'full') {
|
||||
my ($w, $h) = ($size =~ /^(\d+)x(\d+)$/);
|
||||
return "[[img bad size \"$size\"]]" unless (defined $w && defined $h);
|
||||
|
||||
my $outfile = "$config{destdir}/$dir/${w}x${h}-$base";
|
||||
$imglink = "$dir/${w}x${h}-$base";
|
||||
will_render($params{page}, $imglink);
|
||||
|
||||
if (-e $outfile && (-M srcfile($file) >= -M $outfile)) {
|
||||
$r = $im->Read($outfile);
|
||||
return "[[img failed to read $outfile: $r]]" if $r;
|
||||
}
|
||||
else {
|
||||
$r = $im->Read(srcfile($file));
|
||||
return "[[img failed to read $file: $r]]" if $r;
|
||||
|
||||
$r = $im->Resize(geometry => "${w}x${h}");
|
||||
return "[[img failed to resize: $r]]" if $r;
|
||||
|
||||
my @blob = $im->ImageToBlob();
|
||||
writefile($imglink, $config{destdir}, $blob[0], 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$r = $im->Read(srcfile($file));
|
||||
return "[[img failed to read $file: $r]]" if $r;
|
||||
$imglink = $file;
|
||||
}
|
||||
|
||||
add_depends($imglink, $params{page});
|
||||
|
||||
return '<a href="'.
|
||||
IkiWiki::abs2rel($file, IkiWiki::dirname($params{destpage})).
|
||||
'"><img src="'.
|
||||
IkiWiki::abs2rel($imglink, IkiWiki::dirname($params{destpage})).
|
||||
'" alt="'.$alt.'" width="'.$im->Get("width").
|
||||
'" height="'.$im->Get("height").'" /></a>';
|
||||
} #}}}
|
||||
|
||||
1;
|
|
@ -4,8 +4,10 @@ ikiwiki (1.31) UNRELEASED; urgency=low
|
|||
* Change the rss feed title from the wikiname to the page title.
|
||||
Overriding the page title with meta title already overrode the rss feed
|
||||
tittle.
|
||||
* Add an img plugin, based on Christian Mock's img plugin, but stripped
|
||||
down to the bare essentials. Useful for handling large images on websites.
|
||||
|
||||
-- Joey Hess <joeyh@debian.org> Fri, 20 Oct 2006 16:53:36 -0400
|
||||
-- Joey Hess <joeyh@debian.org> Sat, 21 Oct 2006 17:13:47 -0400
|
||||
|
||||
ikiwiki (1.30) unstable; urgency=low
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ added).
|
|||
Some other alternate icons and buttons are also included in the svg file
|
||||
and can be extracted by specifying their names.
|
||||
|
||||
[[img ikiwiki.png alt="bob" size="200x200"]]
|
||||
|
||||
Contributed by Recai Oktaş
|
||||
|
||||
* [[ikiwiki_logo|ikiwiki_old.png]]
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
[[template id=plugin name=img author="Christian Mock"]]
|
||||
[[tag type/chrome]]
|
||||
|
||||
This is an image handling plugin. While ikiwiki supports inlining full-size
|
||||
images by making a [[WikiLink]] that points to the image, using this plugin
|
||||
you can easily scale down an image for inclusion onto a page, providing a
|
||||
link to a full-size version.
|
||||
|
||||
This plugin uses the [ImageMagick](http://www.imagemagick.org/) tools via
|
||||
[PerlMagick](http://www.imagemagick.org/www/perl-magick.html).
|
||||
|
||||
Note that this is a stripped down version of Christian Mock's
|
||||
[[original_img_plugin|contrib/img]].
|
||||
|
||||
## usage
|
||||
|
||||
\[[img image1.jpg size="200x200" alt="clouds"]]
|
||||
|
||||
Or set default values that will be applied to all later images on the page,
|
||||
unless overridden. Useful when including many images on a page.
|
||||
|
||||
\[[img defaults size=200x200 alt="wedding photo"]]
|
||||
\[[img photo1.jpg]]
|
||||
\[[img photo2.jpg]]
|
||||
\[[img photo3.jpg size=200x600]]
|
||||
|
||||
The `alt` parameter is optional. The `size` parameter is also optional,
|
||||
defaulting to full size.
|
Loading…
Reference in New Issue