#!/usr/bin/perl
#
#picsize_finder version 1.41
#this program creates a tab-delimited text database with the image
#filenames and the width and height of the image files in pixels
#an add-on for photoview.pl to automatically
#create the tab delimited gallery.txt file
#works with photoview.pl version 1.31
#Copyright 2000 by Michael K. Goode#
#Version Finish Date: 20 September 2000
#This script is free for use, distribution, and modification#
#The only right I reserve is this header must remain intact, as long as the program#
#is used for its original purpose (creating a text database of image sizes).#
#This header may be removed, if, and only if, a portion of the code is used in a program that does not#
#fulfill either of the two functions of this program#
#The home of this script: http://www.mikegoode.com/web/scripts/#
#please check there for any updates or upgrades or bug fixes and for help files#
#my email address: mike@mikegoode.com#
#if you have any good changes or additions, please email them to me,#
#and I will add them to this program or add new versions of the program#
#to my website and credit you.#
##
#I am not responsible for any damage resulting from the use of this program#
#and I make no guarentees about its performance, specific or implied#
#I am also not able to help anyone with support, other than #
#by providing some basic help info on my website.#
#############################################################
# YOU CAN CHANGE ANYTHING BELOW THIS POINT TO YOUR HEART'S CONTENT#
#############################################################
#you will still have to manually add titles to the gallery.txt file after this program runs
#make sure to manually chmod all directories involved to world writeable,
require 5.005;
#requires perl 5.005 or higher
#require image::size
#this will require image::size.pm in version 2.0, to allow the use of any image file type
$gallery_file = 'lop.txt';
#this is the name of the file you want created with the info in it. 'gallery.txt' suggested
#this is the only variable that must be the same in photoview.pl as it is in this for the program to work
$password = 'nark';
#this password must be entered after the query string when running this program
#this provides no significant security, but it makes it harder for someone who knows that
#you use this program to just run it at will. Why is this a problem? Because that would
#erase any changes you made to the $gallery_file, such as adding titles, as well as using up resources
#the absolute location of your main photo directory; do NOT include trailing slash
$main_directory = '/data/domains/mikegoode.com/public_html/photo/gallery';
#the url of the main photo directory. do not include trailing slash
$directory_url = 'http://www.mikegoode.com/photo/gallery';
#this is the list of subdirectories off your main photo directory that you want scanned
@directories = ('mike1' , 'mike2' , 'mike3' , 'mike4' , 'mike5');
$ext = 'jpg';
#this is the three letter extention of the image files in this directory
#as of this version (v1.31), the program only supports jpegs
#do not include the period in front of the extension
$thumb_ext = '-a';
#this is the ending of the filename added onto the file to indicate a thumbnail
#I recommend keeping it at '-a', unless you already have something different.
#Anything is okay, as long as it is appended onto the end of every thumbnail filename after the
#filename of the corresponding full-size photo.
#example: photo37.jpg = full sized ; photo37thumb = thumbnail
#
##################################
# You do not need to change anything below here ##
##################################
#this checks the password in the query string and kills the program if it does not equal $password
$password_check = "$ENV{'QUERY_STRING'}";
unless($password_check eq $password){
print "Content-type: text/html\n\n no authorization to run program; you are either an unauthorized user or, if you are the sysadmin, you forgot to enter your password in the query string
";
print "for online help, visit GodotWEB Script Online Help";
exit;
}
#the first foreach loop goes through each directory
foreach $directory (@directories) {
$a = "$main_directory" . '/' . "$directory";
chdir("$a") || print "Content-type: text/html\n\n cannot chdir to $a
";
@filenames = glob("*.$ext");
open(A, ">$gallery_file") || print "Content-type: text/html\n\n cannot create $gallery_file";
close(A);
#the open/close statement deletes anything in the gallery.txt file,
#so that it won't end up with too many entries
#####################new code############
#chmod (0666, "$gallery_file");
########################
#the second foreach loop goes through each file in the directory
foreach $filename (@filenames) {
#this skips over any thumbnail file
if($filename =~ m/$thumb_ext/){next}
open(GALLERY, ">>$gallery_file") || print "Content-type: text/html\n\n Could Not write to $gallery_file
";
#this following section prints the thumbnail info by splitting up the full-sized pic
#filename and adding the $thumb_ext and then adding the file extension again
@a = split(/\./, $filename);
$b = shift(@a);
$c = shift(@a);
$thumb = $b . $thumb_ext . '.' . $c;
print GALLERY "$thumb\t";
#writes the thumbnail filename into the gallery.txt file and then runs the &jpegsize subroutine
#to find the size of the thumbnail pic, and writes that to the gallery.txt file too.
if( defined($thumb) && open(THUMB, "<$thumb") ){($x_thumb,$y_thumb) = &jpegsize(\*THUMB)}
print GALLERY "$x_thumb\t";
print GALLERY "$y_thumb\t";
#####################
#this section prints the full sized picture info, and then a newline
print GALLERY "$filename\t";
binmode(PIC); #tells stupid OSs (microsoft) to read images as binary files || microsoft sucks eggs
if( defined($filename) && open(PIC, "<$filename") ){($x,$y) = &jpegsize(\*PIC)}
close(PIC);
print GALLERY "$x\t";
print GALLERY "$y\t\n";
#chmod(644, "$gallery_file); #new code
close(GALLERY);
#######################
}
}
########this prints the ending message##############
#######################################
print "Content-type: text/html\n\n";
print "
and remember to thank Michael Goode"; print " for being such a wonderful guy for writing such a useful program.
"; exit; ############################################ # jpegsize : gets the width and height (in pixels) of a jpeg file# # Andrew Tong, werdna@ugcs.caltech.edu February 14, 1995# # modified slightly by alex@ed.ac.uk# #this subprogram finds out the size of the jpeg image# ############################################ sub jpegsize { my($JPEG) = shift(@_); my($done)=0; my($c1,$c2,$ch,$s,$length, $dummy)=(0,0,0,0,0,0); my($a,$b,$c,$d); if(defined($JPEG)&& read($JPEG, $c1, 1)&& read($JPEG, $c2, 1)&& ord($c1) == 0xFF&& ord($c2) == 0xD8){ while (ord($ch) != 0xDA && !$done) { # Find next marker (JPEG markers begin with 0xFF) # This can hang the program!! while (ord($ch) != 0xFF) { return(0,0) unless read($JPEG, $ch, 1); } # JPEG markers can be padded with unlimited 0xFF's while (ord($ch) == 0xFF) { return(0,0) unless read($JPEG, $ch, 1); } if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3)) { return(0,0) unless read ($JPEG, $dummy, 3); return(0,0) unless read($JPEG, $s, 4); ($a,$b,$c,$d)=unpack("C"x4,$s); return ($c<<8|$d, $a<<8|$b ); } else { # We **MUST** skip variables, since FF's within variable names are # NOT valid JPEG markers return(0,0) unless read ($JPEG, $s, 2); ($c1, $c2) = unpack("C"x2,$s); $length = $c1<<8|$c2; last if (!defined($length) || $length < 2); read($JPEG, $dummy, $length-2); } } } return (0,0); } print "Content-type: text/html\n\n Exiting from wrong place"; print "Something weird must have happened!!! foobar!"; exit; #!/usr/bin/perl # #picsize_finder version 1.31 #this program creates a tab-delimited text database with the image #filenames and the width and height of the image files in pixels #an add-on for photoview.pl to automatically #create the tab delimited gallery.txt file #works with photoview.pl version 1.31 #Copyright 2000 by Michael K. Goode# #Version Finish Date: 20 September 2000 #This script is free for use, distribution, and modification# #The only right I reserve is this header must remain intact, as long as the program# #is used for its original purpose (creating a text database of image sizes).# #This header may be removed, if, and only if, a portion of the code is used in a program that does not# #fulfill either of the two functions of this program# #The home of this script: http://www.mikegoode.com/web/scripts/# #please check there for any updates or upgrades or bug fixes and for help files# #my email address: mike@mikegoode.com# #if you have any good changes or additions, please email them to me,# #and I will add them to this program or add new versions of the program# #to my website and credit you.# ## #I am not responsible for any damage resulting from the use of this program# #and I make no guarentees about its performance, specific or implied# #I am also not able to help anyone with support, other than # #by providing some basic help info on my website.# ############################################################# # YOU CAN CHANGE ANYTHING BELOW THIS POINT TO YOUR HEART'S CONTENT# ############################################################# #you will still have to manually add titles to the gallery.txt file after this program runs #make sure to manually chmod all directories involved to world writeable, #and, because this program (at least on my server running Apache), is not properly creating the #$gallery_file files if they don't exist, you may have to manually create blank text files in your directory require 5.005; #requires perl 5.005 or higher #require image::size #this will require image::size.pm in version 2.0, to allow the use of any image file type $gallery_file = 'lop.txt'; #this is the name of the file you want created with the info in it. 'gallery.txt' suggested #this is the only variable that must be the same in photoview.pl as it is in this for the program to work $password = 'nark'; #this password must be entered after the query string when running this program #this provides no significant security, but it makes it harder for someone who knows that #you use this program to just run it at will. Why is this a problem? Because that would #erase any changes you made to the $gallery_file, such as adding titles, as well as using up resources #the absolute location of your main photo directory; do NOT include trailing slash $main_directory = '/data/domains/mikegoode.com/public_html/photo/gallery'; #the url of the main photo directory. do not include trailing slash $directory_url = 'http://www.mikegoode.com/photo/gallery'; #this is the list of subdirectories off your main photo directory that you want scanned @directories = ('mike1' , 'mike2' , 'mike3' , 'mike4' , 'mike5'); $ext = 'jpg'; #this is the three letter extention of the image files in this directory #as of this version (v1.31), the program only supports jpegs #do not include the period in front of the extension $thumb_ext = '-a'; #this is the ending of the filename added onto the file to indicate a thumbnail #I recommend keeping it at '-a', unless you already have something different. #Anything is okay, as long as it is appended onto the end of every thumbnail filename after the #filename of the corresponding full-size photo. #example: photo37.jpg = full sized ; photo37thumb = thumbnail # ################################## # You do not need to change anything below here ## ################################## #this checks the password in the query string and kills the program if it does not equal $password $password_check = "$ENV{'QUERY_STRING'}"; unless($password_check eq $password){ print "Content-type: text/html\n\n no authorization to run program; you are either an unauthorized user or, if you are the sysadmin, you forgot to enter your password in the query stringand remember to thank Michael Goode"; print " for being such a wonderful guy for writing such a useful program.
"; exit; ############################################ # jpegsize : gets the width and height (in pixels) of a jpeg file# # Andrew Tong, werdna@ugcs.caltech.edu February 14, 1995# # modified slightly by alex@ed.ac.uk# #this subprogram finds out the size of the jpeg image# ############################################ sub jpegsize { my($JPEG) = shift(@_); my($done)=0; my($c1,$c2,$ch,$s,$length, $dummy)=(0,0,0,0,0,0); my($a,$b,$c,$d); if(defined($JPEG)&& read($JPEG, $c1, 1)&& read($JPEG, $c2, 1)&& ord($c1) == 0xFF&& ord($c2) == 0xD8){ while (ord($ch) != 0xDA && !$done) { # Find next marker (JPEG markers begin with 0xFF) # This can hang the program!! while (ord($ch) != 0xFF) { return(0,0) unless read($JPEG, $ch, 1); } # JPEG markers can be padded with unlimited 0xFF's while (ord($ch) == 0xFF) { return(0,0) unless read($JPEG, $ch, 1); } if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3)) { return(0,0) unless read ($JPEG, $dummy, 3); return(0,0) unless read($JPEG, $s, 4); ($a,$b,$c,$d)=unpack("C"x4,$s); return ($c<<8|$d, $a<<8|$b ); } else { # We **MUST** skip variables, since FF's within variable names are # NOT valid JPEG markers return(0,0) unless read ($JPEG, $s, 2); ($c1, $c2) = unpack("C"x2,$s); $length = $c1<<8|$c2; last if (!defined($length) || $length < 2); read($JPEG, $dummy, $length-2); } } } return (0,0); } print "Content-type: text/html\n\n Exiting from wrong place"; print "Something weird must have happened!!! foobar!"; exit;