View Single Post
Old 01-20-2008, 03:10 PM  
ServerGenius
Confirmed User
 
Join Date: Feb 2002
Location: Amsterdam
Posts: 9,377
How much did I earn? This will generate thumbs from all files in a folder and can also apply filters like sharpen.


Code:
#!/usr/bin/perl

sub read_dir{
        my $dir_path = @ARGV[0];
        my $ext = "\.(gif|jpg|JPG|GIF|jpeg|JPEG)";
        chdir($dir_path);
        my $dir = $dirname;
        opendir (DIR, $dir) or die $!;
        #my @dir = readdir DIR;
        rewinddir(DIR);
        my @imgFiles = grep /$ext/, readdir DIR;
        closedir DIR;
        return @imgFiles;
}

my $th_size = @ARGV[1];
my $mi_size = @ARGV[2];
my $convert_executable = @ARGV[3];

my $th_sharpen = ' ';
my $th_level = ' ';
        # my $th_sharpen = ' -unsharp 1.0x1.0+1.0+0.0 ';
        # // radius x sigma + amount + threshold
        # my $th_level   = ' -level 6,90%,1.0 ';
my $mi_sharpen = ' ';
my $mi_level = ' ';

my $counter = 0;

$dirname = '.';
my @files = &read_dir($dirname);
foreach my $f(@files) {
        if ($counter==10) {
                print(" ");
                $counter=0;
        }
        $fnew = $f;
        $fnew =~ s/\./\.thumb./;
        $fnew = 'thumbs/' . $fnew;
        print ".";
        $counter++;
        system($convert_executable." -size ".($th_size*2)."x".($th_size*2)." -thumbnail ".$th_sharpen.$th_level.$th_size."x".$th_size." '".$f."' '".$fnew."'");
        if ($mi_size!=0) {
                print ":";
                system($convert_executable." -thumbnail ".$mi_sharpen.$mi_level.$mi_size."x".$mi_size." '".$f."' 'medium/".$f."'");
        }
__________________
| http://www.sinnerscash.com/ | ICQ: 370820 | Skype: SinnersCash | AdultWhosWho |

Last edited by ServerGenius; 01-20-2008 at 03:11 PM..
ServerGenius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote