Попалось однажды под руку куча фоток, которые нужно было смасштабировать (уменьшить на n%).
Так появилась следующая небольшая прога на языке Perl, в которой пользователю выдается графическое меню. Единственный минус - никак не смог побороть кириллическое название директорий, поэтому работает только с латиницей названными директориями.
#!/usr/bin/perl use File::Find; use Tk; use Tk::ProgressBar; use locale; use Encode qw(encode decode); my $file; my @file_result; my $percent_done=0; my $mw = MainWindow->new; $mw->geometry("700x600"); $mw->title("DOWNLOADING FILES"); my $main_frame = $mw->Frame()->pack(-side => 'top', -fill => 'x'); my $top_frame = $mw->Frame(-background => "grey")->pack(-side => 'top',-fill => 'x'); my $FileName_frame = $mw->Frame(-background => "black")->pack(-side => "top",-fill => 'x'); my $To_Dir_frame = $mw->Frame(-background => "black")->pack(-side => "top",-fill => 'x'); my $Mashtab = $mw->Frame(-background => "black")->pack(-side => "top",-fill => 'x');
$Mashtab->Label(-text => " Scale,%: ", -background => "black",-foreground => "yellow")->pack(-side => "left"); my $Mashtab = $Mashtab->Entry(-background => "white",-foreground => "red")->pack(-side => "left");
$mw->Button(-text => "CLOSE",-background => "grey",-foreground => "red", -command =>sub{exit})->pack(-ipady => 12,-side => "top",-fill => "x"); $mw->Button(-text => "START",-background => "grey",-foreground => "green", -command => \&Load_entry)->pack(-ipady => 12,-side => "top",-fill => "x");
my $text_frame = $mw->Frame(-background => "black")->pack(-side => "top",-fill => 'x'); $top_frame->Label(-text => "Resize JPG",-background => "grey")->pack(-side => "top"); $FileName_frame->Label(-text => " Directory ", -background => "black",-foreground => "yellow")->pack(-side => "left");
$To_Dir_frame->Label(-text => " Directory to unload ", -background => "black",-foreground => "yellow")->pack(-side => "left");
my $clear_text = $text_frame->Button(-text => "Clear Window",-background => "black",-foreground => "green",-command => \&clear_entry)->pack(-side => "top"); my $paste_text = $text_frame->Text(-background => "white",-foreground => "black")->pack(-ipadx => 60,-ipady => 40,-side => "top"); my $FileName_button = $FileName_frame->Button(-text => " Review ",-command => \&OpenFile)->pack(-side => "left"); my $To_Dir_button = $To_Dir_frame->Button(-text => " Review ",-command => \&To_Dir)->pack(-side => "left");
sub OpenFile { my $dirname = $mw->chooseDirectory( ); $paste_text->insert("end", "Dir is: $dirname\n"); $file = $dirname; }
sub To_Dir { my $dirname = $mw->chooseDirectory( ); $paste_text->insert("end", "Dir for resize photo: $dirname\n"); $file_resize = $dirname; }
sub Load_entry { find(\&do_file, $file); sub do_file { if (/\.JPG|jpg$/) { push @file_result,$_; } } $mw = MainWindow->new(-title => 'ProgressBar'); $mw->geometry("200x60+0+0"); my $Status = $mw->Frame(-background => "black")->pack(-side => "top",-fill => 'x'); $Status->Label(-text => ".....", -background => "black",-foreground => "yellow")->pack(-side => "left"); my $progress = $mw->ProgressBar( -width => 30, -length => 200, -pady => 25, -anchor => 'w', -from => 0, -to => 100, -blocks => 1, -colors => [0, 'green', 50, 'yellow' , 80, 'red'], -variable => \$percent_done )->pack(-fill => 'x'); for ($i = 0; $i < scalar @file_result; $i++) { $count = ($i+1)*100/(scalar @file_result); $percent_done = get_percent($file_result[$i],$count);
if ($count == 100) { $Status->Label(-text => "Finished!", -background => "black",-foreground => "yellow")->pack(-side => "left");} $mw->update; }
sub get_percent { my $file_conv = $_[0]; my $i_count = $_[1]; my $scale = $Mashtab->get()."%"; $paste_text->insert("end", "$file/$file_conv --> Scale: $scale\n"); $dst_name = join('_',$file_conv,'resize.jpg'); `convert "$file/$file_conv" -resize $scale "$file_resize/$dst_name"`; return $i_count; } quit; MainLoop; } MainLoop; |
Обновлено 05.04.2016 11:28