| | 154 | sub resize_thumb { |
|---|
| | 155 | my ($self, $size, $file, $type, $out) = @_; |
|---|
| | 156 | |
|---|
| | 157 | my ($w, $h) = imgsize($file); |
|---|
| | 158 | my $biggest = ($w > $h) ? $w : $h; |
|---|
| | 159 | my $ratio = $size / $biggest; |
|---|
| | 160 | my $neww = int($w * $ratio); |
|---|
| | 161 | my $newh = int($h * $ratio); |
|---|
| | 162 | my $p = Image::Magick->new($neww."x$newh"); |
|---|
| | 163 | $p->Read($file); |
|---|
| | 164 | $p->Resize(width=>$neww, height=>$newh, filter=>'Lanczos'); |
|---|
| | 165 | $p->UnsharpMask( |
|---|
| | 166 | radius => 1.5, |
|---|
| | 167 | sigma => 1, |
|---|
| | 168 | amount => 1.5, |
|---|
| | 169 | threshold => 0.003 |
|---|
| | 170 | ); |
|---|
| | 171 | $p->Set(quality => 75); |
|---|
| | 172 | |
|---|
| | 173 | ($$out) = $p->ImageToBlob(); |
|---|
| | 174 | return; |
|---|
| | 175 | } |
|---|
| | 176 | |
|---|
| 151 | | my $image = Image::Imlib2->load($file) |
|---|
| 152 | | or die "Image load ($file) failed: $!"; |
|---|
| 153 | | |
|---|
| 154 | | my ($w, $h) = ($image->width(), $image->height()); |
|---|
| 155 | | |
|---|
| 156 | | $self->log(LOGINFO, "Original width x height: $w x $h"); |
|---|
| 157 | | |
|---|
| 158 | | my $quality = $self->config('GalleryThumbQuality') || 'preview'; |
|---|
| 159 | | $quality = 'normal' if $quality ne 'preview'; |
|---|
| 160 | | $quality = 'normal' if $self->client->param('size') ne 'thumb'; |
|---|
| 161 | | |
|---|
| 162 | | $self->log(LOGINFO, "Scaling to $size with quality: $quality"); |
|---|
| 163 | | |
|---|
| 164 | | my $thumb = $image->create_scaled_image( |
|---|
| 165 | | $w > $h ? |
|---|
| 166 | | ($size, 0) |
|---|
| 167 | | : (0, $size) |
|---|
| 168 | | ); |
|---|
| 169 | | |
|---|
| 170 | | $self->log(LOGINFO, "sharpening $file size $size"); |
|---|
| 171 | | #$thumb->sharpen(1) if $quality eq 'normal'; |
|---|
| 172 | | |
|---|
| 173 | | my ($fh, $filename) = tempfile("galleryXXXXXXXX", SUFFIX => ".jpg"); |
|---|
| 174 | | $thumb->save($filename); |
|---|
| 175 | | seek($fh, 0, 0); |
|---|
| 176 | | local $/; |
|---|
| 177 | | $$out = <$fh>; |
|---|
| 178 | | unlink($filename); |
|---|
| | 180 | my ($w, $h) = imgsize($file); |
|---|
| | 181 | my $biggest = ($w > $h) ? $w : $h; |
|---|
| | 182 | my $ratio = $size / $biggest; |
|---|
| | 183 | my $neww = int($w * $ratio); |
|---|
| | 184 | my $newh = int($h * $ratio); |
|---|
| | 185 | my $p = Image::Magick->new($neww."x$newh"); |
|---|
| | 186 | $p->Read($file); |
|---|
| | 187 | $p->Resize(width=>$neww, height=>$newh, filter=>'Lanczos'); |
|---|
| | 188 | $p->UnsharpMask( |
|---|
| | 189 | radius => 1.5, |
|---|
| | 190 | sigma => 1, |
|---|
| | 191 | amount => 1.0, |
|---|
| | 192 | threshold => 0.03 |
|---|
| | 193 | ); |
|---|
| | 194 | $p->Set(quality => 75); |
|---|
| | 195 | |
|---|
| | 196 | ($$out) = $p->ImageToBlob(); |
|---|