- { return $m->interp->apply_escapes("$IMGURL/$path", "u"); }
-
- my $tail = "scale.$sz/$path";
- my $thumb = "$CACHE/$tail";
- my $thumburl = $m->interp->apply_escapes("$CACHEURL/$tail", "u");
- my $st = stat $thumb;
- if (defined $st && $st->mtime > $me->{mtime}) { return $thumburl; }
- return
- $m->interp->apply_escapes("$SCRIPTURL/$path", "u") . "?scale=$scale"
- unless $forcep;
-
- my ($dir, $base, $ext) = TrivGal::split_path $thumb;
- my $ty = $TYPE{lc $ext} or die "unknown type `$ext'";
-
- my $img = $me->{img};
- unless (defined $img) {
- my $exif = new Image::ExifTool;
- $exif->ExtractInfo($me->{imgpath});
- my $orient = $exif->GetValue("Orientation", "ValueConv");
- $img = $me->{img} = Image::Imlib2->load($me->{imgpath});
- if (defined $orient) {
- my ($rot, $flip) = @{$ORIENT{$orient}};
- if ($rot) { $img->image_orientate($rot); }
- if ($flip) { $img->flip_horizontal(); }
+ { $url = $m->interp->apply_escapes("$IMGURL/$path", "u"); }
+ else {
+ my $tail = "scale.$sz/$path";
+ my $thumb = "$CACHE/$tail";
+ my $thumburl = $m->interp->apply_escapes("$CACHEURL/$tail", "u");
+
+ my $st = stat $thumb;
+ if ($st && $st->mtime > $me->{mtime})
+ { $url = $thumburl; }
+ elsif (!$forcep) {
+ $url =
+ $m->interp->apply_escapes("$SCRIPTURL/$path", "u") .
+ "?scale=$scale";
+ } else {
+ my $img = $me->{img};
+ unless (defined $img) {
+ $img = $me->{img} = Graphics::Magick->new;
+ _check_gm $img->Read($me->{imgpath});
+ }
+
+ my ($dir, undef, $ext) = TrivGal::split_path $thumb;
+ $img = $img->Clone;
+ my $new = "$TMP/t$$-thumb$ext";
+ _check_gm $img->Resize(geometry => $sz);
+ make_path $TMP, { mode => 0771 };
+ _check_gm $img->Write($new);
+ make_path $dir, { mode => 0771 };
+ rename $new, $thumb;
+ $url = $thumburl;