#!/usr/bin/perl 


### thumbnail generation with Image-magick 
### Image-magick has some problems with resizing jpgs below 128x90 :-/



if ( eval "require Image::Size" ) {
    Image::Size->import();
}
else {
    print(
        "The perl module Image::Size is not installed\n
	Don't panic :-\), it is easy to install\n
	Take a look at the README file\n "
    );
    exit(0);
}



@all_pics       = glob("./*.JPG");
@all_pics2 = glob("./*.jpg");
push ( @all_pics , @all_pics2 );
@thumbnails = @all_pics;
$number_of_pics = @all_pics;
print("\nfound $number_of_pics Jpeg files\n");




   print("generating thumbnails...\n ");
    @thumbnails = @all_pics;
    
    if ( -e "thumb" ) { }
    else {
        system("mkdir thumb");
    }
    $counter =1;
    while (@thumbnails) {
        $name = shift @thumbnails;
        $name = substr( $name, 2 );
        print("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
        ( $x, $y ) = imgsize("$name");
        if ( $x / $y >= 800 / 600 )

          # Image-magick seems to be buggy .. this is the only way to generate thumbnails with a useable size     
        {
            system("convert -geometry 160x10000000  -quality 85 \"$name\" thumb/\"$name\"");
        }
        else {
            system("convert -geometry x120   -quality 85 \"$name\" thumb/\"$name\"");
        }
         
        
        print("$counter/$number_of_pics ");
        $counter++;
    }
    print(" \[ done \]\n");


