+
+ # If we're being asked for just the box, make a new image with just the box.
+ # 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.
+ if ($infobox eq 'box') {
+ my ($img, $width, $height);
+
+ # This is slow, but should fortunately almost never happen, so don't bother
+ # special-casing it.
+ if (!defined($dbwidth) || !defined($dbheight)) {
+ $img = read_original_image($r, $filename, $id, $dbwidth, $dbheight, 0);
+ $width = $img->Get('columns');
+ $height = $img->Get('rows');
+ @$img = ();
+ } else {
+ $img = Image::Magick->new;
+ $width = $dbwidth;
+ $height = $dbheight;
+ }
+
+ if (defined($xres) && defined($yres)) {
+ ($width, $height) = scale_aspect($width, $height, $xres, $yres);
+ }
+ $height = 24;
+ $img->Set(size=>($width . "x" . $height));
+ $img->Read('xc:white');
+
+ my $info = Image::ExifTool::ImageInfo($fname);
+ 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, quality => 90, depth => 8);
+ $r->log->info("New infobox cache: $width x $height for $id.jpg");
+
+ return ($cachename, 'image/png');
+ }
+
+ my $can_use_qscale = 0;
+ if ($infobox eq 'nobox') {
+ $can_use_qscale = 1;
+ }
+
+ my $img = make_mipmap($r, $filename, $id, $dbwidth, $dbheight, $can_use_qscale, $xres, $yres, @otherres);