summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki/Plugin/img.pm85
-rw-r--r--debian/changelog4
-rw-r--r--doc/logo.mdwn2
-rw-r--r--doc/plugins/img.mdwn28
4 files changed, 118 insertions, 1 deletions
diff --git a/IkiWiki/Plugin/img.pm b/IkiWiki/Plugin/img.pm
new file mode 100644
index 000000000..bde5a3e1a
--- /dev/null
+++ b/IkiWiki/Plugin/img.pm
@@ -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;
diff --git a/debian/changelog b/debian/changelog
index 28f6c9e61..99d01554d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -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
diff --git a/doc/logo.mdwn b/doc/logo.mdwn
index 339457d2f..35ec21748 100644
--- a/doc/logo.mdwn
+++ b/doc/logo.mdwn
@@ -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]]
diff --git a/doc/plugins/img.mdwn b/doc/plugins/img.mdwn
new file mode 100644
index 000000000..4a92cefc4
--- /dev/null
+++ b/doc/plugins/img.mdwn
@@ -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.