Pavel Titov (titov_en) wrote in fotobilder,
Pavel Titov

Improved resize techniques

I always hated doing by hand things that can be automated. One of such things is preparing photos for web - resizing, sharpening etc. Stock Fotobilder can resize photos, but they sometimes greatly loss in quality (especially details) due to standard ImageMagick (bilinear?) resize. On of the well-knowing techniques is a resizing photo step-by-step, sharpening it on every step. It produces result almost equivalent to simple resize + sharpen, but small details are more sharp.

So, I replaced simple resize to such advanced resize on my fotobilder setup.

Now my resizing code is following:
# animated gifs are distorted with 'Resize'
if ($image->Get('format') =~ /graphics interchange/i) {
unless ($FB::ANIMATED_GIF_THUMBS) { # 1st frame
$image->deanimate or $err->(FB::last_error());
$image->Sample('width' => $nw, 'height' => $nh)
or $err->(FB::last_error());
} else {
if($nw < 1000 && $nh < 1000){
# it's a web-sized photo
# let's advanced resize it

$currw = $g_orig->{'width'};
$currh = $g_orig->{'height'};

while<$currw * 0.35 > $nw){
$currw = $currw * 0.35;
$currh = $currh * 0.35;

$image->Resize<'width' => $currw, 'height' => $currh)
or die FB::last_error<);
$image->Sharpen<'radius' => 1, 'sigma' => 1)
or die FB::last_error<);

# original fotobilder simple resize
$image->Resize<'width' => $nw, 'height' => $nh)
or die FB::last_error<);

if<$nw < 1000 && $nh < 1000){
$image->Sharpen<'radius' => 1, 'sigma' => 1)
or die FB::last_error<);
} changes are similar, but with sigma 0.7, it's more applicable for thumbnails. Shrinking image to 35% on every step and sigma values are empiric, I guess they can be improved.


  • 302: lj_dev

    In the interests of consolidating all FotoBilder development-related discussion, we're going to be closing down this community. The same…

  • Development stalled?

    Is the development of Fotobilder held? Stalled? I am asking because there is no activity on the community and there is no link to the Fotobilder…

  • (no subject)

    Does FotoBilder works with Apache2? I installed all the required modules on my debian sarge, and when I restart my apache server, it dies horribly…

  • Post a new comment


    Comments allowed for members only

    Anonymous comments are disabled in this journal

    default userpic