#!/usr/bin/perl
# az Sat Jan 3 19:12:21 2004
package image;
use strict;
use vars qw($debug);
use Image::Size;
use File::Basename;
$debug=0;
my $thumbprefix=".thumb_";
sub start { 1; }
sub story
{
my ($pkg,$path,$filename,$storyr,$titler,$bodyr)=@_;
my $src="$blosxom::datadir$path/$filename.$blosxom::file_extension";
while ($$bodyr =~ s/\[img\]([ \t]+(\S+))?\n(((\S+)[^\n]*(\n|$))+)(\n|$)/handle_imgs($1,$3,$src)/ei)
{
1;
}
return 1;
}
sub handle_imgs
{
my ($class,$liste,$src)=@_;
my $result;
$class=~s/^\s*(\S+)\s*$/$1/;
$class||="thumbs";
$debug and print "doing $liste with $class\n";
$result.="
";
# liste includes comments, need to cleanup
while ($liste)
{
my ($im,$cap);
$liste=~s/^(\S+)(.*)$//m and ($im,$cap)=($1,$2) or last;
$debug and print "found image $im with caption $cap\n";
my ($name,$path)=fileparse($im);
die "no image $im in $src\n" if (!-r "$blosxom::datadir/$path$name");
$cap||=$name;
$debug and print "$name is $name, path is $path, caption is $cap\n";
# thumbnail available?
if (! -r "$blosxom::datadir/$path$thumbprefix$name")
{
print "generating thumbnail for $name\n";
system("convert +profile '*' -scale x75 $blosxom::datadir/$path$name $blosxom::datadir/$path$thumbprefix$name");
}
# figure out size of thumb
my ($x,$y)=imgsize("$blosxom::datadir/$path$thumbprefix$name");
$result.="
";
}
$result.="
\n";
return $result;
}