X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FCommon.pm;h=027268a2c469faeeb2b5d232d91e619753a8b341;hp=e348d32297595b2ac01ba4a12038a349466a8193;hb=133c9fb7f197da55e8b85e98a17ae6a184a28832;hpb=f7c70497096c80290e4a8d5d69fe8417d1aa931f diff --git a/perl/Sesse/pr0n/Common.pm b/perl/Sesse/pr0n/Common.pm index e348d32..027268a 100644 --- a/perl/Sesse/pr0n/Common.pm +++ b/perl/Sesse/pr0n/Common.pm @@ -550,7 +550,6 @@ sub ensure_cached { # We don't care about @otherres since each of these images are # already pretty cheap to generate, but we need the exact width so we can make # one in the right size. - $r->log->warn("BOX: $infobox"); if ($infobox eq 'box') { my ($img, $width, $height); @@ -570,14 +569,23 @@ sub ensure_cached { if (defined($xres) && defined($yres)) { ($width, $height) = scale_aspect($width, $height, $xres, $yres); } - $img->Set(size=>($width . "x24")); + $height = 24; + $img->Set(size=>($width . "x" . $height)); $img->Read('xc:white'); my $info = Image::ExifTool::ImageInfo($fname); - make_infobox($img, $info, $r); + if (!make_infobox($img, $info, $r)) { + # Not enough room for the text, make a tiny dummy transparent infobox + @$img = (); + $img->Set(size=>"1x1"); + $img->Read('null:'); + + $width = 1; + $height = 1; + } $err = $img->write(filename => $cachename); - $r->log->info("New infobox cache: $width x 24 for $id.jpg"); + $r->log->info("New infobox cache: $width x $height for $id.jpg"); return ($cachename, 'image/png'); } @@ -778,7 +786,7 @@ sub make_infobox { } } - return if (scalar @parts == 0); + return 0 if (scalar @parts == 0); # Find the required width my $th = 0; @@ -798,7 +806,7 @@ sub make_infobox { $th = $h if ($h > $th); } - return if ($tw > $img->Get('columns')); + return 0 if ($tw > $img->Get('columns')); my $x = 0; my $y = $img->Get('rows') - 24; @@ -827,6 +835,8 @@ sub make_infobox { $img->Annotate(text=>$part->[0], font=>$font, pointsize=>12, x=>int($x), y=>int($y)); $x += ($img->QueryFontMetrics(text=>$part->[0], font=>$font, pointsize=>12))[4]; } + + return 1; } sub gcd {