]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/Common.pm
Fix another bug relating to the "-1x-1" (ie. original size, but still with
[pr0n] / perl / Sesse / pr0n / Common.pm
index e348d32297595b2ac01ba4a12038a349466a8193..6f45d55d903186aa6dc489f208519fd98574887f 100644 (file)
@@ -35,7 +35,7 @@ BEGIN {
                require Sesse::pr0n::Config_local;
        };
 
-       $VERSION     = "v2.60";
+       $VERSION     = "v2.65";
        @ISA         = qw(Exporter);
        @EXPORT      = qw(&error &dberror);
        %EXPORT_TAGS = qw();
@@ -408,7 +408,7 @@ sub make_mipmap {
                my $large_enough = 1;
                for my $i (0..($#res/2)) {
                        my ($xres, $yres) = ($res[$i*2], $res[$i*2+1]);
-                       if ($xres > $new_mmwidth || $yres > $new_mmheight) {
+                       if ($xres == -1 || $xres > $new_mmwidth || $yres > $new_mmheight) {
                                $large_enough = 0;
                                last;
                        }
@@ -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,30 @@ 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)) {
+                               $img->Quantize(colors=>16, dither=>'False');
+
+                               # Since the image is grayscale, ImageMagick overrides us and writes this
+                               # as grayscale anyway, but at least we get rid of the alpha channel this
+                               # way.
+                               $img->Set(type=>'Palette');
+                       } else {
+                               # 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");
+                       $err = $img->write(filename => $cachename, quality => 90, depth => 8);
+                       $r->log->info("New infobox cache: $width x $height for $id.jpg");
                        
                        return ($cachename, 'image/png');
                }
@@ -778,7 +793,7 @@ sub make_infobox {
                }
        }
 
-       return if (scalar @parts == 0);
+       return if (scalar @parts == 0);
 
        # Find the required width
        my $th = 0;
@@ -798,7 +813,7 @@ sub make_infobox {
                $th = $h if ($h > $th);
        }
 
-       return if ($tw > $img->Get('columns'));
+       return if ($tw > $img->Get('columns'));
 
        my $x = 0;
        my $y = $img->Get('rows') - 24;
@@ -827,6 +842,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 {