<pre>
#!/usr/bin/perl
#______________________________________________________________________________
# Title : make_VGA_640x480_size_jpeg_pictures
# Usage :
# Function : GIF format thumbnail from JPEG files.
# Example : 
# Keywords :
# Options :
# Author : j@bio.cc
# Category :
# Returns :
# Version : 20041106
#------------------------------------------------------------------------------
# this takes only JPEG format files as I use 'djpeg' program.
@picture_files=@{&read_file_names_only('.', "e=jpg,jpeg,JPG")};
&make_VGA_640x480_size_jpeg_pictures(\@picture_files);
#______________________________________________________________________________
# Title : make_VGA_640x480_size_jpeg_pictures
# Usage :
# Function : GIF format thumbnail from JPEG files.
# Example : 
# Keywords :
# Options :
# Author : j@bio.cc
# Category :
# Returns :
# Version : 20041106
#------------------------------------------------------------------------------
sub make_VGA_640x480_size_jpeg_pictures{
my(@picture_files, $thumbnail_index_file, $i, $thumbnail_file);
@picture_files=@{$_/> $thumbnail_index_file="index_VGA_640x480_size_pictures.html";
open(HTML_PIC_FILE, ">$thumbnail_index_file") || die "\n Can not open $thumbnail_index_file \n";
print HTML_PIC_FILE "";
for($i=0; $i<@picture_files; $i++){
if($picture_files[$i=~ /^(e?g)$/i){" target="_blank" rel="noopener">
$file_name_base=$1;
$jpeg_ext=$2;
$thumbnail_file="$file_name_base\_thumb.gif";
$vga_file ="$file_name_base\_VGA_640x480_size.gif";
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Make thumbnails INDEX file of pictures which are over 18k byte size
#_____________________________________________________________
if(-s $picture_files[$i > 80000){ ### this is about right for 640x480 ??
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Make thumbnails and VGA files using djpeg
#_____________________________________________________________
system("djpeg -scale 1/4 -gif -colors 128 -dither ordered -outfile $vga_file $picture_files
system("djpeg -scale 1/8 -gif -colors 128 -dither ordered -outfile $thumbnail_file $picture_files[$i") unless (-s $thumbnail_file);
print "$picture_fileshas been processed\n";
print HTML_PIC_FILE "\n";
}else{
print HTML_PIC_FILE "\n";
}
}
print HTML_PIC_FILE "<\/html>";
if(-s $thumbnail_index_file){
print "\n $thumbnail_index_file has been made \n\n";
}else{
die "\n $thumbnail_index_file has not been made\n";
}
}
#________________________________________________________________________
# Title : read_file_names_only
# Usage : @all_files=@{&read_file_names_only(
# Function : read any file names and REMOVES the '.', '..' and dir entries.
# And then put in array. This checks if anything is a real file.
# You can use 'txt' as well as '.txt' as extension
# You can put multiple file extension (txt, doc, ....)
# and multiple dir path (/usr/Perl, /usr/local/Perl....)
# It will fetch all files wanted in all the direc specified
#
# It can handle file glob eg)
# @all_files=@{&read_file_names_only(\$abs_path_dir_name, 'G1_*.txt')};
# for all txt files starting with 'G1_'
#
# Example : @all_files=@{&read_file_names_only(\$abs_path_dir_name, ..)};
# @all_files=@{&read_file_names_only(\$dir1, '.pl', '.txt')};
# @all_files=@{&read_file_names_only(\$dir1, '.', \$dir2, \$dir3, 'e=pl')};
# @all_files=@{&read_file_names_only(\$abs_path_dir_name, 'G1_*.txt')};
# @all_files=@{&read_file_names_only(\$abs_path_dir_name, \@target_file_names)};
#
# Warning : This does not report '.', '..'
# Only file names are reported. Compare with &read_any_dir
# extension size should be less than 15 char.
# It sorts the results!
# Keywords : filename only, filename_only, read_files_only, read files
# get_file_names_only, get_files_only, read_files_only
# Options : "extension name". If you put , 'pl' as an option, it will show
# files only with '.pl' extension.
# '-p' for path also included resulting in '/path/path/file.ext'
# rather than 'file.ext' in output @array
# '-s' for sorting the results
# e='xxx' for extention xxx
# '.pl' for files extended by '.pl'
# 'pl' for files extended by 'pl', same as above
# D= for dir name input
# d= for dir name input
#
# Category :
# Version : 3.2
#--------------------------------------------------------------------
sub read_file_names_only{
my($in_dir, $i, $j, $x, $k, $dir, @final_files, @possible_dirs, $sort_opt, $ext, @extensions,
$path_include, @in, $glob_given, @files_globed, @in_dir, $pwd, $extension_given,
%target_file_names, @target_file_names, @read_files);
$pwd=`pwd`; chomp($pwd);
$in_dir=$pwd;
@in=@_;
print "\n# read_file_names_only: input are @in" if $verbose;
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Directory entry and opts detection
#_________________________________________
for($k=0; $k < @in; $k++){
if ( $ineq '.'){ push(@in_dir,$pwd); splice(@in, $k, 1); $k--; next }
if( !(ref($in[$k))){
print "\n# read_file_names_only: $inis not a reference";
if($in[$k=~/D=(\S+)/i){
print "\n# read_file_names_only : $1 is used as input dir ";
push(@in_dir, $1); splice(@in, $k, 1); $k--; next; }
if( -d "$in){
print "\n# read_file_names_only: $in[$k is a dir";
if($in/> $path_include=1; ## If the input dir has '/', I assume path should be added to out file names
print "\n# read_file_names_only: \$path_include is set to 1";
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Removes the last slash '/' of input dir name
#________________________________________________
if($in[$k=~/\/$/){ chop($in}
push(@in_dir, $in[$k);
splice(@in, $k, 1); $k--; next;
}
if(!(-f $inand $in[$k =~ /^\-p *$/ ){ ## somehow, ' *' is essential
$path_include=1;
splice(@in, $k, 1); $k--;
}elsif(!(-f $inand $in[$k =~ /^\-s *$/ ){$sort_opt=1; splice(@in, $k, 1); $k--;
}else{
print "\n# (W) read_file_names_only: $innot a file, nor dir, a file extnsion?\n";
}
}elsif(ref($in[$k)){
if(ref($ineq 'SCALAR'){
if( -d ${$in[$k}){
if(${$inchop(${$in[$k}) }
push(@in_dir,${$in/> splice(@in, $k, 1);
$k--;
}elsif(!(-f $in[$k) and ${$in=~ /^\-p$/ ){$path_include=1; splice(@in, $k, 1); $k--;
}elsif(!(-f $in[$k) and ${$in=~ /^\-s$/ ){$sort_opt=1; splice(@in, $k, 1); $k--;}
}elsif(ref($in[$k) eq 'ARRAY'){
@target_file_names=@{$insplice(@in, $k, 1); $k--;
for($x=0; $x < @target_file_names; $x++){ # making a hash out of @array
$target_file_names{$target_file_names[$x}=$target_file_names/> }
}
}
}
if(@in_dir < 1){ push(@in_dir, $pwd) }
if($verbose){
print "\n# read_file_names_only: Final input directories are : @in_dir";
print "\n# read_file_names_only: going to \'File name and extension detection\' stage with \@in";
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# File name and extension detection
#_________________________________________
for $dir (@in_dir){
print "\n# read_file_names_only: changing to subdir \'$dir\'" if $verbose;
chdir($dir);
print "\n# read_file_names_only: trying to detect extension name from \@in: @in\n" if $verbose;
for($k=0; $k < @in; $k++){
if( !(ref($in[$k))){
if($in/> $glob_given=1;
#~~~~~~~~~~~~~~~~~~~~~ Reads globbed files and attaches path if opt -p is set
if($path_include==1){ @final_files=map{ "$dir/$_" } <$in[$k>;
}else{ @final_files=<$in}
splice(@in, $k, 1); $k--;
}elsif(!(-f $in[$k) and $in=~/e=\.?(\S+)/){
$temp=$1;
if($temp=~/\,/){ push(@extensions, split(/\,/, $temp));
}else{ push(@extensions, $temp); }
splice(@in, $k, 1); $k--;
$extension_given =1;
}elsif(!(-f $in[$k) and $in=~/\.*(\S+)/){
$temp=$1;
if($temp=~/^e=$/){ next } ## Empty extension entry case.
print "\n# read_file_names_only: pushing $1 as an extension" if $verbose;
$extension_given =1; push(@extensions, $temp);
splice(@in, $k, 1); $k--;
}elsif(!(-f $in[$k) and $in=~/^([^\-{0,8})$/){ ## extension name can not be larger than 8 chars
print "\n# read_file_names_only: pushing $1 as an extension" if $verbose;
$extension_given =1; push(@extensions, $1);
splice(@in, $k, 1); $k--;
}
}elsif(ref($in/> if(ref($in[$k) eq 'SCALAR'){
if(${$in/> $glob_given=1;
if($path_include==1){ @final_files=map{ "$dir/$_" } <${$in[$k}>;
}else{ @final_files=<${$in}
splice(@in, $k, 1); $k--;
}elsif(!(-f ${$in[$k}) and ${$in=~/e=(\S+)/ ){ $extension_given = 1;
$temp=$1;
if($temp=~/\,/){ push(@extensions, split(/\,/, $temp));
}else{ push(@extensions, $temp); }
splice(@in, $k, 1); $k--;
}elsif(!(-f ${$in[$k}) and ${$in=~/^\.?(\S+)/ ){$extension_given =1;
push(@extensions, $1); splice(@in, $k, 1); $k--;
}
}
}
}
chdir($pwd);
}
if( $glob_given == 1 and $extension_given !=1 ){ # when glob input is given only(without any extension input!
print "\n# read_file_names_only: You used glob for file name, but without extension name\n" if $verbose;
return(\@final_files);
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
# Main READING PART
#_________________________________________________
print "\n# read_file_names_only: \@in_dir is @in_dir, @extensions\n";
for($k=0; $k< @in_dir; $k++){
chdir($in_dir[$k) or die "\n# read_file_names_only: could not get into $in_dir/> opendir(DIR1, ".");
@read_files = readdir(DIR1);
print "\n# read_file_names_only: content of \@read_files in $in_dir[$k : @read_files\n" if $verbose;
if(@read_files < 1){ print "\n# read_file_names_only: ERROR??, \@read_files is empty\n\n\n"; }
for($i=0; $i < @read_files; $i ++){
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# If the user has specified the target file names
#____________________________________________________
if( @target_file_names > 0){
if( -f "$read_filesand -s $target_file_names{$read_files[$i} ){ ##
if($extension_given ==1 ){
for $ext (@extensions){
if( $read_files=~ /\.$ext$/){
if($path_include==1){
push(@final_files, "$in_dir[$k\/$read_files);
}else{
push(@final_files, "$read_files[$i" );
}
}
}
}else{ ## reading everything !!!
push(@final_files, $read_files/> }
}
}else{
if( -f "$read_files[$i" ){ ##
if($extension_given ==1 ){
for $ext (@extensions){
if( $read_files=~ /\.?$ext$/){
if($path_include==1){
push(@final_files, "$in_dir[$k\/$read_files);
}else{
push(@final_files, "$read_files[$i" );
}
}
}
}else{ ## reading everything !!!
push(@final_files, $read_files$i);
}
}
}
}
chdir($pwd);
}
@final_files=sort @final_files if $sort_opt == 1;
return(\@final_files);
}
댓글 0