Created
February 27, 2012 03:25
-
-
Save evandhoffman/1921103 to your computer and use it in GitHub Desktop.
2 different ways to resize a ton of pics for a digital photo frame.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| find /src/ -iname \*jpg -execdir convert -scale 800x533 -quality 80 {} /target/{} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| # Resize all images in a directory for the Insignia 7" Digital photo | |
| # frame (Model: NS-DPF0712G), 800x480 resolution. | |
| use strict; | |
| use warnings; | |
| use File::Find; | |
| use Image::Magick; | |
| my $source_dir = '/src/'; | |
| my $target_dir = '/target/'; | |
| my $resize_width = 800; | |
| my $resize_height = 480; | |
| my $scale_dimensions = $resize_width . 'x' . ($resize_height + 200); | |
| my $crop_dimensions = $resize_width . 'x' . $resize_height; | |
| my $crop_gravity = 'Center'; | |
| my ($image, $x); | |
| my $convert_count = 0; | |
| my $start = time; | |
| find(\&wanted, $source_dir); | |
| my $end = time; | |
| my $elapsed = $end - $start; | |
| my $speed = $convert_count / $elapsed; | |
| print "Total converted files: $convert_count, elapsed time: $elapsed, speed: $speed/second\n"; | |
| sub wanted { | |
| my ($dev,$ino,$mode,$nlink,$uid,$gid); | |
| my $image = Image::Magick->new; | |
| $image->Set(gravity=>$crop_gravity); | |
| if ( (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && | |
| /^.*jpg\z/si) { | |
| $x = $image->Read($_); | |
| warn "$x" if "$x"; | |
| $x = $image->Scale(geometry=>$scale_dimensions); | |
| warn "$x" if "$x"; | |
| my $width = $image->Get('width'); | |
| if ($width >= $resize_width) { | |
| # Don't crop images that are in portrait orientation. | |
| $x = $image->Crop(geometry=>$crop_dimensions); | |
| warn "$x" if "$x"; | |
| } | |
| $x = $image->Write(filename=>$target_dir . '/' . $_, quality=>80); | |
| warn "$x" if "$x"; | |
| $convert_count++; | |
| my $elapsed = time - $start; | |
| my $speed = $elapsed > 0 ? $convert_count / $elapsed : 0; | |
| print "converted $convert_count: $_\n"; | |
| if ($convert_count % 25 == 0) { | |
| print "Rate so far: $speed/second\n"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment