]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/Common.pm
Small simplification.
[pr0n] / perl / Sesse / pr0n / Common.pm
index 72be2184d99a84bcc9245939a791ffa488cc6b9e..4839285dba1b99ea3e790f90a5296d9fdfcb39e4 100644 (file)
@@ -207,20 +207,20 @@ sub get_dbh {
 
 sub get_disk_location {
        my ($r, $id) = @_;
-        my $dir = POSIX::floor($id / 256);
+       my $dir = POSIX::floor($id / 256);
        return $Sesse::pr0n::Config::image_base . "images/$dir/$id.jpg";
 }
 
 sub get_cache_location {
        my ($id, $width, $height) = @_;
-        my $dir = POSIX::floor($id / 256);
+       my $dir = POSIX::floor($id / 256);
 
        return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-nobox.jpg";
 }
 
 sub get_infobox_cache_location {
        my ($id, $width, $height, $dpr) = @_;
-        my $dir = POSIX::floor($id / 256);
+       my $dir = POSIX::floor($id / 256);
 
        if ($dpr == 1) {
                return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box.png";
@@ -248,7 +248,7 @@ sub ensure_disk_location_exists {
 
 sub get_mipmap_location {
        my ($r, $id, $width, $height) = @_;
-        my $dir = POSIX::floor($id / 256);
+       my $dir = POSIX::floor($id / 256);
 
        return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-mipmap-$width-$height.jpg";
 }
@@ -574,8 +574,6 @@ sub read_original_image {
 sub ensure_cached {
        my ($r, $filename, $id, $dbwidth, $dbheight, $xres, $yres, @otherres) = @_;
 
-       my ($new_dbwidth, $new_dbheight);
-
        my $fname = get_disk_location($r, $id);
        unless (defined($xres) && (!defined($dbwidth) || !defined($dbheight) || $xres < $dbwidth || $yres < $dbheight || $xres == -1)) {
                return ($fname, undef);
@@ -591,8 +589,13 @@ sub ensure_cached {
                        error($r, 'System is in overload mode, not doing any scaling');
                }
 
-               my $img;
-               ($img, $new_dbwidth, $new_dbheight) = make_mipmap($r, $filename, $id, $dbwidth, $dbheight, $xres, $yres, @otherres);
+               my ($img, $new_dbwidth, $new_dbheight) = make_mipmap($r, $filename, $id, $dbwidth, $dbheight, $xres, $yres, @otherres);
+
+               # Update the SQL database if it doesn't contain the required info
+               if (!defined($dbwidth) && defined($new_dbwidth)) {
+                       log_info($r, "Updating width/height for $id: $new_dbwidth x $new_dbheight");
+                       update_image_info($r, $id, $new_dbwidth, $new_dbheight);
+               }
 
                while (defined($xres) && defined($yres)) {
                        my ($nxres, $nyres) = (shift @otherres, shift @otherres);
@@ -616,7 +619,7 @@ sub ensure_cached {
                        my $sf = "1x1";
 
                        if ($xres != -1) {
-                               $cimg->Resize(width=>$nwidth, height=>$nheight, filter=>$filter, 'sampling-factor'=>$sf);
+                               $cimg->Resize(width=>$nwidth, height=>$nheight, filter=>$filter);
                        }
 
                        # Strip EXIF tags etc.
@@ -654,12 +657,6 @@ sub ensure_cached {
                        }
                }
        }
-       
-       # Update the SQL database if it doesn't contain the required info
-       if (!defined($dbwidth) && defined($new_dbwidth)) {
-               log_info($r, "Updating width/height for $id: $new_dbwidth x $new_dbheight");
-               update_image_info($r, $id, $new_dbwidth, $new_dbheight);
-       }
 
        return ($cachename, 'image/jpeg');
 }