my ($r, $id, $width, $height, $infobox) = @_;
my $dir = POSIX::floor($id / 256);
- if ($infobox) {
+ if ($infobox eq 'both') {
return get_base($r) . "cache/$dir/$id-$width-$height.jpg";
- } else {
+ } elsif ($infobox eq 'nobox') {
return get_base($r) . "cache/$dir/$id-$width-$height-nobox.jpg";
+ } else {
+ return get_base($r) . "cache/$dir/$id-$width-$height-box.png";
}
}
my ($r, $filename, $id, $dbwidth, $dbheight, $infobox, $xres, $yres, @otherres) = @_;
my $fname = get_disk_location($r, $id);
- unless (defined($xres) && (!defined($dbwidth) || !defined($dbheight) || $xres < $dbheight || $yres < $dbwidth || $xres == -1)) {
- return ($fname, 0);
+ if ($infobox ne 'box') {
+ unless (defined($xres) && (!defined($dbwidth) || !defined($dbheight) || $xres < $dbheight || $yres < $dbwidth || $xres == -1)) {
+ return ($fname, undef);
+ }
}
my $cachename = get_cache_location($r, $id, $xres, $yres, $infobox);
$r->log->warn("In overload mode, not scaling $id to $xres x $yres");
error($r, 'System is in overload mode, not doing any scaling');
}
+
+ # 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.
+ $r->log->warn("BOX: $infobox");
+ 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, $id, $dbwidth, $dbheight);
+ $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);
+ }
+ $img->Set(size=>($width . "x24"));
+ $img->Read('xc:white');
+
+ my $info = Image::ExifTool::ImageInfo($fname);
+ make_infobox($img, $info, $r);
+
+ $err = $img->write(filename => $cachename);
+ $r->log->info("New infobox cache: $width x 24 for $id.jpg");
+
+ return ($cachename, 'image/png');
+ }
my $img = make_mipmap($r, $fname, $id, $dbwidth, $dbheight, $xres, $yres, @otherres);
$cimg->Resize(width=>$nwidth, height=>$nheight, filter=>$filter);
}
- if (($nwidth >= 800 || $nheight >= 600 || $xres == -1) && $infobox == 1) {
+ if (($nwidth >= 800 || $nheight >= 600 || $xres == -1) && $infobox ne 'nobox') {
my $info = Image::ExifTool::ImageInfo($fname);
make_infobox($cimg, $info, $r);
}
}
}
}
- return ($cachename, 1);
+ return ($cachename, 'image/jpeg');
}
sub get_mimetype_from_filename {
# Find the event and file name
my ($event,$filename,$xres,$yres);
- my $infobox = 1;
- if ($r->uri =~ m#^/([a-zA-Z0-9-]+)/original/(nobox/)?([a-zA-Z0-9._()-]+)$#) {
+ my $infobox = 'both';
+ if ($r->uri =~ m#^/([a-zA-Z0-9-]+)/original/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) {
$event = $1;
$filename = $3;
- } elsif ($r->uri =~ m#^/([a-zA-Z0-9-]+)/(\d+)x(\d+)/(nobox/)?([a-zA-Z0-9._()-]+)$#) {
+ $infobox = 'nobox' if (defined($2) && $2 eq 'nobox/');
+ $infobox = 'box' if (defined($2) && $2 eq 'box/');
+ } elsif ($r->uri =~ m#^/([a-zA-Z0-9-]+)/(\d+)x(\d+)/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) {
$event = $1;
$filename = $5;
$xres = $2;
$yres = $3;
- $infobox = 0 if (defined($4));
- } elsif ($r->uri =~ m#^/([a-zA-Z0-9-]+)/(nobox/)?([a-zA-Z0-9._()-]+)$#) {
+ $infobox = 'nobox' if (defined($4) && $4 eq 'nobox/');
+ $infobox = 'box' if (defined($4) && $4 eq 'box/');
+ } elsif ($r->uri =~ m#^/([a-zA-Z0-9-]+)/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) {
$event = $1;
$filename = $3;
$xres = -1;
$yres = -1;
- $infobox = 0 if (defined($2));
+ $infobox = 'nobox' if (defined($2) && $2 eq 'nobox/');
+ $infobox = 'box' if (defined($2) && $2 eq 'box/');
}
my ($id, $dbwidth, $dbheight);
$dbheight = $ref->{'height'};
# Scale if we need to do so
- my ($fname,$thumbnail) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $infobox, $xres, $yres);
+ my ($fname, $mime_type) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $infobox, $xres, $yres);
# Output the image to the user
- my $mime_type;
- if ($thumbnail) {
- $mime_type = "image/jpeg";
- } else {
+ if (!defined($mime_type)) {
$mime_type = Sesse::pr0n::Common::get_mimetype_from_filename($filename);
}
$r->content_type($mime_type);