]> git.sesse.net Git - pr0n/commitdiff
Support a new form of image: box/, which is exactly the opposite of nobox/
authorSteinar H. Gunderson <sesse@debian.org>
Mon, 26 May 2008 18:59:39 +0000 (20:59 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Mon, 26 May 2008 18:59:39 +0000 (20:59 +0200)
(ie. the infobox only, no image), as a PNG file. Will be used by the fullscreen
part soonish.

perl/Sesse/pr0n/Common.pm
perl/Sesse/pr0n/Image.pm
perl/Sesse/pr0n/pr0n.pm

index eb111ceb9dc513c50987ba7e9683c66706592217..e348d32297595b2ac01ba4a12038a349466a8193 100644 (file)
@@ -218,10 +218,12 @@ sub get_cache_location {
        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";
        }
 }
 
@@ -528,8 +530,10 @@ sub ensure_cached {
        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);
@@ -541,6 +545,42 @@ sub ensure_cached {
                        $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);
 
@@ -576,7 +616,7 @@ sub ensure_cached {
                                $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);
                        }
@@ -616,7 +656,7 @@ sub ensure_cached {
                        }
                }
        }
-       return ($cachename, 1);
+       return ($cachename, 'image/jpeg');
 }
 
 sub get_mimetype_from_filename {
index e298dc317277e1e2613345776ba9923e84374eec..da45cfbd098571baece177482b5f795549c2d04f 100644 (file)
@@ -15,22 +15,26 @@ sub handler {
 
        # 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);
@@ -48,13 +52,10 @@ sub handler {
        $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);
index 16b696414202144b42c76ef93767118782c4874b..eeb93b0a7aa544df4b88db2e350a6d24e9ec4e04 100644 (file)
@@ -72,7 +72,7 @@ sub handler {
                 $uri =~ /^\/\+all\/?$/ ||
                 $uri =~ /^\/\+tags\/[a-zA-Z0-9-]+\/?$/) {
                return Sesse::pr0n::Index::handler($r);
-       } elsif ($uri =~ m#^/[a-zA-Z0-9-]+/(\d+x\d+/|original/)?(nobox/)?[a-zA-Z0-9._()-]+$#) {
+       } elsif ($uri =~ m#^/[a-zA-Z0-9-]+/(\d+x\d+/|original/)?((?:no)?box/)?[a-zA-Z0-9._()-]+$#) {
                return Sesse::pr0n::Image::handler($r);
        }