]> sipb.mit.edu Git - ikiwiki.git/commitdiff
add pagenumber parameter
authorchrysn <chrysn@fsfe.org>
Mon, 7 Apr 2014 09:32:25 +0000 (11:32 +0200)
committerchrysn <chrysn@fsfe.org>
Mon, 7 Apr 2014 09:32:25 +0000 (11:32 +0200)
this allows picking a page from a pdf. also, this enhances performance
greatly when rendering pdfs, as only the first page is rasterized.
(otherwise, imagemagick would treat the pdf as a list of images, work
with all of them, until finally only the first page gets saved). the
default parameter of 0 will select the single image contained in typical
image files anyway, so no specialcasing between single- and multifile
containers is needed.

IkiWiki/Plugin/img.pm
doc/ikiwiki/directive/img.mdwn

index ae681f9e65ca975f6dfedcfd87b0b80307975613..fe0ba2ef1388dd5f741a170b9521a7f4b57c2adf 100644 (file)
@@ -66,12 +66,16 @@ sub preprocess (@) {
        my $base = IkiWiki::basename($file);
        my $issvg = $base=~s/\.svg$/.png/i;
        my $ispdf = $base=~s/\.pdf$/.png/i;
+       my $pagenumber = exists($params{pagenumber}) ? int($params{pagenumber}) : 0;
+       if ($pagenumber != 0) {
+               $base = "p$pagenumber-$base";
+       }
 
        eval q{use Image::Magick};
        error gettext("Image::Magick is not installed") if $@;
        my $im = Image::Magick->new();
        my $imglink;
-       my $r = $im->Read($srcfile);
+       my $r = $im->Read("$srcfile\[$pagenumber]");
        error sprintf(gettext("failed to read %s: %s"), $file, $r) if $r;
        
        my ($dwidth, $dheight);
index cda62b58f04cdad190f2b9a72b28546416185652..08d15898702ca800c825cc33cb610c34bec50f23 100644 (file)
@@ -28,6 +28,9 @@ to the full size version. By default it does; set "link=somepage" to link
 to another page instead, or "link=no" to disable the link, or
 "link=http://url" to link to a given url.
 
+The `pagenumber` parameter selects which of multiple images should be rendered;
+this is relevant mainly for GIF and PDF source images.
+
 You can also set default values that will be applied to all later images on
 the page, unless overridden. Useful when including many images on a page.