Last active
March 16, 2019 10:31
-
-
Save hikiko/cbded768323e9a5f23bf97754f4005ca to your computer and use it in GitHub Desktop.
old script - supposed to create thumbs from images and thumbs.html file (not tested recently)
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 File::Path qw(rmtree); | |
use File::Copy; | |
use File::MimeInfo; | |
use Image::Magick; | |
my @files; | |
my @thumbs; | |
my $dir; | |
my $thdir; | |
my $ft; | |
my $filetype; | |
my $im; | |
my $image; | |
my $x; | |
$dir = $ARGV[0]; | |
if ( -d $dir ) { | |
opendir(DIR,$dir) or die $!; | |
@files = (readdir DIR) or die $!; | |
closedir(DIR) or die $!; | |
$thdir = $dir."thumbs/"; | |
if ( -d $thdir ) { | |
rmtree($thdir,0,0) or die $!; | |
} | |
$ft = File::MimeInfo->new(); | |
mkdir( $thdir ) or die $!; | |
foreach ( @files ) { | |
next if ( $_ eq "." || $_ eq ".." || -d "$dir$_" ); | |
$filetype = $ft->globs($_); | |
if ( $filetype eq "image/jpeg"||$filetype eq "image/png"|| $filetype eq "image/gif" ) { | |
copy($dir."$_",$thdir."$_") or die $!; | |
} | |
} | |
opendir(DIR2,$thdir) or die $!; | |
@thumbs = (readdir DIR2) or die $!; | |
@thumbs = sort(@thumbs); | |
closedir(DIR2) or die $!; | |
if ( -f $dir."thumbs.html" ) { | |
unlink($dir."thumbs.html"); | |
} | |
open FILE, ">>", $dir."thumbs.html" or die $!; | |
print FILE qq[]; | |
foreach ( @thumbs ) { | |
$im = Image::Magick->new(); | |
next if ( $_ eq "." || $_ eq ".."); | |
$x = $im->Read("$thdir$_"); | |
die $x."\n" if ( $x ); | |
$x = $im->Resize(width=>200, height=>200); | |
die $x."\n" if ( $x ); | |
$x = $im->Write("$thdir$_"); | |
die $x."\n" if ( $x ); | |
$im = ""; | |
print FILE qq[ | |
<a href="$_"><img src="thumbs/$_" alt="image: $_" /></a> | |
]; | |
} | |
print FILE qq[]; | |
close FILE or die $!; | |
} | |
else { | |
die "there is no such directory!\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment