#!/usr/bin/perl use Image::Size; sub get_thumbnail { my($file) = @_; $file =~ m|^(.*)/([^/]+)\.([^/\.]+)$|si; my($path, $filename, $ext) = ($1,$2,$3); $thumbpath = $path . '/.thumbnails/' . $filename . '.gif'; if(-f $thumbpath) { my($thumbwidth, $thumbheight) = imgsize($thumbpath); return ($thumbpath, $thumbwidth, $thumbheight); } $thumbdir = $path . '/.thumbnails/'; mkdir $thumbdir unless -d $thumbdir; my($imwidth, $imheight) = imgsize($file); @st=stat($file); # return undef if $st[7] > 250000; #my($filer) = $file; #my($thumbpathr) = $thumbpath; #$filer =~ s|([ '`\)\(])|\\$1|gs; #$thumbpathr =~ s|([ '`\)\(])|\\$1|gs; # $cmd = "convert -antialias -geometry '100x100>' $filer $thumbpathr"; # system $cmd; use Image::Magick; $p = new Image::Magick; #print STDERR "Reading $file for thumbnail generation.\n"; $p->Read($file); if( ($imwidth > 100 || $imheight > 100) || ($ext !~ m/(gif|jpg|png)/) || (scalar(@$p) > 1) ) { @$p = ($p->[0]); $p->Resize(geometry=>'100x100>'); #print STDERR "Writing thumbnail $thumbpath\n"; $p->Write($thumbpath); undef $p; my($thumbwidth, $thumbheight) = imgsize($thumbpath); return ($thumbpath, $thumbwidth, $thumbheight); } undef $p; return ($file, $imwidth, $imheight); } 1;