Skip to content

Instantly share code, notes, and snippets.

@ojplg
Created March 1, 2015 19:38
Show Gist options
  • Save ojplg/4a2e3ee158e43eee12db to your computer and use it in GitHub Desktop.
Save ojplg/4a2e3ee158e43eee12db to your computer and use it in GitHub Desktop.
#!/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