|
|
@@ -205,35 +205,52 @@ sub get_page_image { |
|
|
|
$size = $qs->{maxWidth}; |
|
|
|
} |
|
|
|
|
|
|
|
my $src; |
|
|
|
my $dst; |
|
|
|
|
|
|
|
if ( !defined $id ) { |
|
|
|
return gen_error_img($wh, $size, "No page found"); |
|
|
|
$src = $conf->{path}{error_img}; |
|
|
|
} |
|
|
|
else { |
|
|
|
$src = sprintf("%s/%s/%s.jpeg", |
|
|
|
$conf->{path}{global}, $conf->{path}{original}, $id); |
|
|
|
} |
|
|
|
|
|
|
|
my $original = sprintf("%s/%s/%s.jpeg", |
|
|
|
$conf->{path}{global}, $conf->{path}{original}, $id); |
|
|
|
|
|
|
|
my $cache_file = sprintf("%s/%s/%s-original.jpeg", |
|
|
|
$conf->{path}{global}, $conf->{path}{images}, $id); |
|
|
|
|
|
|
|
if ( defined $wh && defined $size ) { |
|
|
|
$cache_file = sprintf("%s/%s/%s-%s-%s.jpeg", |
|
|
|
$conf->{path}{global}, $conf->{path}{images}, $id, $wh, $size); |
|
|
|
if ( defined $id ) { |
|
|
|
$dst = sprintf("%s/%s/%s-%s-%s.jpeg", |
|
|
|
$conf->{path}{global}, $conf->{path}{cache}, $id, $wh, $size); |
|
|
|
} |
|
|
|
else { |
|
|
|
$dst = sprintf("%s/%s/error_img-%s-%s.jpeg", |
|
|
|
$conf->{path}{global}, $conf->{path}{cache}, $wh, $size); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
gen_thumbnail($original, $cache_file, $wh, $size) if !-r $cache_file; |
|
|
|
|
|
|
|
my $img=''; |
|
|
|
my $imgfile; |
|
|
|
|
|
|
|
if ( -r $cache_file ) { |
|
|
|
open(IMG, $cache_file) || fatal_api_error(500, "Thumbnail generation failed"); |
|
|
|
binmode(IMG); |
|
|
|
while(<IMG>) { $img.=$_; } |
|
|
|
close(IMG); |
|
|
|
if ( !defined $dst ) { |
|
|
|
$imgfile = $src; |
|
|
|
} |
|
|
|
else { |
|
|
|
$img = gen_error_img($wh, $size, "No Image"); |
|
|
|
if ( ! -r $dst ) { |
|
|
|
system(sprintf("convert %s -resize %s%s %s", |
|
|
|
$src, |
|
|
|
$wh eq 'h' ? 'x' : '', |
|
|
|
$size, |
|
|
|
$dst |
|
|
|
)); |
|
|
|
} |
|
|
|
|
|
|
|
$imgfile = $dst; |
|
|
|
} |
|
|
|
|
|
|
|
my $img = ''; |
|
|
|
open(IMG, $imgfile) || fatal_api_error(500,"Failed to generate image"); |
|
|
|
binmode(IMG); |
|
|
|
while(<IMG>) { $img.=$_; } |
|
|
|
close(IMG); |
|
|
|
|
|
|
|
return $img; |
|
|
|
} |
|
|
|
|
|
|
@@ -251,17 +268,19 @@ sub gen_thumbnail { |
|
|
|
} |
|
|
|
|
|
|
|
sub gen_error_img { |
|
|
|
my($wh, $size, $text) = @_; |
|
|
|
my($wh, $size) = @_; |
|
|
|
|
|
|
|
my $w = $size; |
|
|
|
my $h = $size; |
|
|
|
my $src = $conf->{page}{error_img}; |
|
|
|
my $dst = sprintf("%s/error_img-%s%s.jpeg", $conf->{path}{cache}, $wh, $size); |
|
|
|
|
|
|
|
$h = int($w*(sqrt(2))) if $wh eq 'w'; |
|
|
|
$w = int($h/(sqrt(2))) if $wh eq 'h'; |
|
|
|
if ( ! -r $dst ) { |
|
|
|
system(sprintf("convert %s -resize %s%s %s", |
|
|
|
$src, |
|
|
|
$wh eq 'h' ? 'x' : '', |
|
|
|
$size, |
|
|
|
$dst)); |
|
|
|
} |
|
|
|
|
|
|
|
my $img = GD::Simple->new($w, $h); |
|
|
|
$img->string($text); |
|
|
|
return $img->jpeg; |
|
|
|
} |
|
|
|
|
|
|
|
# create an empty document object. |