X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FQscaleProxy.pm;h=f62690247e4fe4f9189860dc3a436924ef53e33a;hp=f534d78f9ae279c6aa1820f9083e8473948dac55;hb=09260885c52013320acd21d7ce262e12def7301f;hpb=8ccd04f16bde7455ef0bfdb67586b29d33b4cb2e diff --git a/perl/Sesse/pr0n/QscaleProxy.pm b/perl/Sesse/pr0n/QscaleProxy.pm index f534d78..f626902 100644 --- a/perl/Sesse/pr0n/QscaleProxy.pm +++ b/perl/Sesse/pr0n/QscaleProxy.pm @@ -16,7 +16,7 @@ BEGIN { $has_qscale = 1; }; if ($@) { - Apache2::ServerUtil->server->log_error("Could not load the qscale module ($@); continuing with ImageMagick only."); + print STDERR "Could not load the qscale module ($@); continuing with ImageMagick only.\n"; } } @@ -129,9 +129,10 @@ sub Resize { my $samp_v2 = 1; my $filter; - if ($args{'filter'} eq 'Lanczos' || - $args{'filter'} eq 'Mitchell') { + if ($args{'filter'} eq 'Lanczos') { $filter = $qscale::LANCZOS; + } elsif ($args{'filter'} eq 'Mitchell') { + $filter = $qscale::MITCHELL; } else { die "Unknown filter " . $args{'filter'}; } @@ -158,6 +159,9 @@ sub write { return $self->{'magick'}->write(%args); } + # For some reason we seem to get conditions of some sort when using + # qscale for this, but not when using ImageMagick. Thus, we put the + # atomic-write code here and not elsewhere in pr0n. my $filename = $args{'filename'}; my $quality = $args{'quality'}; @@ -170,11 +174,17 @@ sub write { die "Unknown interlacing mode " . $args{'interlace'}; } - my $ret = qscale::qscale_save_jpeg($self->{'qscale'}, $filename, $quality, $jpeg_mode); + my $tmpname = $filename . "-tmp-$$-" . int(rand(100000)); + unlink($filename); + my $ret = qscale::qscale_save_jpeg($self->{'qscale'}, $tmpname, $quality, $jpeg_mode); if ($ret == 0) { - return 0; + if (rename($tmpname, $filename)) { + return 0; + } else { + return "400 Image renaming to from $tmpname to $filename failed: $!"; + } } else { - return "400 Image saving to $filename failed"; + return "400 Image saving to $tmpname failed"; } }