X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FCommon.pm;fp=perl%2FSesse%2Fpr0n%2FCommon.pm;h=27993647cab189c2d926ab5c3d690e1de7cf6edd;hp=8a426987bf2fbb90614f7f36620aaf37cbbcaae2;hb=c8c8d4ba8a2e5a3c8b6a6b787a354f72c29964e2;hpb=d43ebfec566433afc04bfec5df55f69752df7399 diff --git a/perl/Sesse/pr0n/Common.pm b/perl/Sesse/pr0n/Common.pm index 8a42698..2799364 100644 --- a/perl/Sesse/pr0n/Common.pm +++ b/perl/Sesse/pr0n/Common.pm @@ -219,17 +219,6 @@ sub get_cache_location { return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-nobox.$format"; } -sub get_infobox_cache_location { - my ($id, $width, $height, $dpr) = @_; - my $dir = POSIX::floor($id / 256); - - if ($dpr == 1) { - return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box.png"; - } else { - return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box\@$dpr.png"; - } -} - sub ensure_disk_location_exists { my ($r, $id) = @_; my $dir = POSIX::floor($id / 256); @@ -708,69 +697,6 @@ sub make_cache { } } -sub ensure_infobox_cached { - my ($r, $filename, $id, $dbwidth, $dbheight, $dpr, $xres, $yres) = @_; - - my ($new_dbwidth, $new_dbheight); - - my $fname = get_disk_location($r, $id); - my $cachename = get_infobox_cache_location($id, $xres, $yres, $dpr); - my $err; - if (! -r $cachename or (-M $cachename > -M $fname)) { - # If we are in overload mode (aka Slashdot mode), refuse to generate - # new thumbnails. - if (Sesse::pr0n::Overload::is_in_overload($r)) { - log_warn($r, "In overload mode, not scaling $id to $xres x $yres"); - error($r, 'System is in overload mode, not doing any scaling'); - } - - # We need the exact width so we can make one in the right size. - my ($width, $height); - - # This is slow, but should fortunately almost never happen, so don't bother - # special-casing it. - if (!defined($dbwidth) || !defined($dbheight)) { - my $img = read_original_image($r, $filename, $id, $dbwidth, $dbheight, 0); - $new_dbwidth = $width = $img->Get('columns'); - $new_dbheight = $height = $img->Get('rows'); - } else { - $width = $dbwidth; - $height = $dbheight; - } - my $img = Image::Magick->new; - - if (defined($xres) && defined($yres)) { - ($width, $height) = scale_aspect($width, $height, $xres, $yres); - } - $height = 24 * $dpr; - $img->Set(size=>($width . "x" . $height)); - $img->Read('xc:white'); - - my $info = Image::ExifTool::ImageInfo($fname); - if (make_infobox($img, $info, $r, $dpr)) { - $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); - log_info($r, "New infobox cache: $width x $height for $id.jpg"); - } - - return ($cachename, 'image/png'); -} - sub get_mimetype_from_filename { my $filename = shift; my MIME::Type $type = $mimetypes->mimeTypeOf($filename); @@ -778,8 +704,8 @@ sub get_mimetype_from_filename { return $type; } -sub make_infobox { - my ($img, $info, $r, $dpr) = @_; +sub make_infobox_parts { + my ($info) = @_; # The infobox is of the form # "Time - date - focal length, shutter time, aperture, sensitivity, exposure bias - flash", @@ -894,57 +820,7 @@ sub make_infobox { } } - return 0 if (scalar @parts == 0); - - # Find the required width - my $th = 0; - my $tw = 0; - - for my $part (@parts) { - my $font; - if ($part->[1]) { - $font = '/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf'; - } else { - $font = '/usr/share/fonts/truetype/msttcorefonts/Arial.ttf'; - } - - my (undef, undef, $h, undef, $w) = ($img->QueryFontMetrics(text=>$part->[0], font=>$font, pointsize=>12*$dpr)); - - $tw += $w; - $th = $h if ($h > $th); - } - - return 0 if ($tw > $img->Get('columns')); - - my $x = 0; - my $y = $img->Get('rows') - 24*$dpr; - - # Hit exact DCT blocks - $y -= ($y % 8); - - my $points = sprintf "%u,%u %u,%u", $x, $y, ($img->Get('columns') - 1), ($img->Get('rows') - 1); - my $lpoints = sprintf "%u,%u %u,%u", $x, $y, ($img->Get('columns') - 1), $y; - $img->Draw(primitive=>'rectangle', stroke=>'white', fill=>'white', points=>$points); - $img->Draw(primitive=>'line', stroke=>'black', strokewidth=>$dpr, points=>$lpoints); - - # Start writing out the text - $x = ($img->Get('columns') - $tw) / 2; - - my $room = ($img->Get('rows') - $dpr - $y - $th); - $y = ($img->Get('rows') - $dpr) - $room/2; - - for my $part (@parts) { - my $font; - if ($part->[1]) { - $font = '/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf'; - } else { - $font = '/usr/share/fonts/truetype/msttcorefonts/Arial.ttf'; - } - $img->Annotate(text=>$part->[0], font=>$font, pointsize=>12*$dpr, x=>int($x), y=>int($y)); - $x += ($img->QueryFontMetrics(text=>$part->[0], font=>$font, pointsize=>12*$dpr))[4]; - } - - return 1; + return @parts; } sub gcd { @@ -1048,10 +924,6 @@ sub get_all_cache_urls { push @ret, "/$event/$1x$2/$filename"; } elsif ($fname =~ /^$id-(\d+)-(\d+)-nobox\.jpg$/) { push @ret, "/$event/$1x$2/nobox/$filename"; - } elsif ($fname =~ /^$id--1--1-box\.png$/) { - push @ret, "/$event/box/$filename"; - } elsif ($fname =~ /^$id-(\d+)-(\d+)-box\.png$/) { - push @ret, "/$event/$1x$2/box/$filename"; } else { log_warn($r, "Couldn't find a purging URL for $fname"); }