]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Add an img plugin, based on Christian Mock's img plugin, but stripped
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sat, 21 Oct 2006 21:59:44 +0000 (21:59 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sat, 21 Oct 2006 21:59:44 +0000 (21:59 +0000)
  down to the bare essentials. Useful for handling large images on websites.

IkiWiki/Plugin/img.pm [new file with mode: 0644]
debian/changelog
doc/logo.mdwn
doc/plugins/img.mdwn [new file with mode: 0644]

diff --git a/IkiWiki/Plugin/img.pm b/IkiWiki/Plugin/img.pm
new file mode 100644 (file)
index 0000000..bde5a3e
--- /dev/null
@@ -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;
index 28f6c9e6105ddb77f4be2c238b72e9752d4ddee9..99d01554d3b43879a2a353597e9b3def24fd3771 100644 (file)
@@ -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.
   * 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
 
 
 ikiwiki (1.30) unstable; urgency=low
 
index 339457d2fc92c39e03f771e371fd731381ebb126..35ec21748e80e8b4f2bda2eb91846c9c4dc47810 100644 (file)
@@ -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.
 
   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]] 
   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 (file)
index 0000000..4a92cef
--- /dev/null
@@ -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.