Created
March 1, 2015 19:38
-
-
Save ojplg/4a2e3ee158e43eee12db to your computer and use it in GitHub Desktop.
This file contains 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 | |
use strict; | |
use warnings; | |
# imgpg -- create an index page with thumbnails for some images in a directory | |
# open files in directory | |
# use image magick to create thumbnails | |
# write a quick index.html which includes thumbnails and links to each image | |
# `convert $file -resize 100x100 thumb_$file` | |
my %thumbs = (); | |
opendir (my $dh, ".") || die "cannot open directory"; | |
my @files = readdir ($dh); | |
foreach my $file (@files) { | |
if ( ! ($file =~ /\d+\.jpg$/ ) ){ | |
next; | |
} | |
my $thumb = "thumb_$file"; | |
print "$thumb -> $file\n"; | |
$thumbs{$thumb} = $file; | |
`convert $file -resize 100x100 $thumb`; | |
} | |
closedir $dh; | |
open my $ifh, "> index.html"; | |
print $ifh "<html>\n"; | |
print $ifh " <body>\n"; | |
foreach my $thumb (sort keys %thumbs){ | |
print $ifh " <a href=\"$thumbs{$thumb}\"><img src=\"$thumb\"></a>\n"; | |
} | |
print $ifh " </body>\n"; | |
print $ifh "</html>\n"; | |
close $ifh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment