2009-01-08 02:10:44 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use File::Basename;
|
|
|
|
use Image::ExifTool;
|
|
|
|
|
|
|
|
mkdir("/tmp/photopackager", 0777) unless (-d "/tmp/photopackager");
|
|
|
|
|
|
|
|
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
|
|
|
|
$year = $year+1900;
|
|
|
|
$mon = $mon+1;
|
|
|
|
$stamp = "$year"."$mon"."$mday"."$hour"."$min"."$sec";
|
|
|
|
|
|
|
|
open(LOG, ">/tmp/photopackager/$stamp.log");
|
|
|
|
|
|
|
|
|
|
|
|
$convertpath = $ARGV[0]."/Contents/Resources/convert";
|
|
|
|
print LOG "Convert Path: $convertpath\n";
|
|
|
|
|
|
|
|
$compositepath = $ARGV[0]."/Contents/Resources/composite";
|
|
|
|
print LOG "Composite Path: $compositepath\n";
|
|
|
|
|
|
|
|
$watermarkpath = $ARGV[0]."/Contents/Resources/Watermark.png";
|
|
|
|
print LOG "Watermark Path: $watermarkpath\n";
|
|
|
|
|
|
|
|
#reset the variables
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
#feed the array
|
|
|
|
foreach (@ARGV) {
|
|
|
|
if ($_ =~ /.jpg$/i || $_ =~ /.gif$/i || $_ =~ /.jpeg$/i ||
|
|
|
|
$_ =~ /.png$/i || $_ =~ /.tiff$/i || $_ =~ /.tif$/i ) {
|
|
|
|
($files[$i], $directory) = fileparse($_);
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$newdir = $directory."temp";
|
|
|
|
print LOG "Creating temporary directory ".$newdir."\n";
|
|
|
|
|
|
|
|
mkdir("$newdir", 0777);
|
|
|
|
|
|
|
|
$num_files = @files;
|
|
|
|
$total = $num_files;
|
|
|
|
$xml_file = $directory."temp/photos.xml";
|
|
|
|
|
|
|
|
print LOG "Opening XML File ".$xml_file."\n";
|
|
|
|
|
|
|
|
open(XML, ">$xml_file");
|
|
|
|
print XML '<?xml version="1.0"?>'."\n";
|
|
|
|
print XML '<album>'."\n";
|
|
|
|
|
|
|
|
print LOG "Processing Photos.\n";
|
|
|
|
|
|
|
|
## Sort the files in Alphabetical order
|
|
|
|
print LOG "Sorting photos.\n";
|
|
|
|
sort {lc($a) cmp lc($b)} (@files);
|
|
|
|
#sort(@files);
|
|
|
|
|
|
|
|
foreach $file (sort {lc($a) cmp lc($b) } (@files)) {
|
|
|
|
|
|
|
|
## Sanitize the filename.
|
|
|
|
$new_file = $file;
|
|
|
|
$new_file =~ s/thm_|mid_|\s|%20|\'|\"//gi;
|
|
|
|
|
|
|
|
$reg = $directory."temp/".$new_file;
|
|
|
|
$mid = $directory."temp/mid_".$new_file;
|
|
|
|
$thm = $directory."temp/thm_".$new_file;
|
|
|
|
|
|
|
|
$input = $directory.$file;
|
|
|
|
|
|
|
|
print LOG $num_files.". ".$input;
|
|
|
|
|
|
|
|
$i = $total - $num_files;
|
|
|
|
$num_files--;
|
|
|
|
|
|
|
|
## Create Commands.
|
2009-01-08 05:31:13 +00:00
|
|
|
`\"$convertpath\" -monitor -quality 80 -resize 1280x1280 \"$input\" \"$reg\"`; print LOG ".";
|
|
|
|
`\"$compositepath\" -monitor -dissolve 15 -gravity \"SouthEast\" \"$watermarkpath\" \"$reg\" \"$reg\"`; print LOG ".";
|
|
|
|
`\"$convertpath\" -monitor -quality 80 -sharpen 1 -resize 500x500 \"$input\" \"$mid\"`; print LOG ".";
|
|
|
|
`\"$convertpath\" -monitor -quality 50 -resize 150x150 -quality 50 \"$input\" \"$thm\"`; print LOG ".";
|
2009-01-08 02:10:44 +00:00
|
|
|
## create XML entry for that file.
|
|
|
|
print XML '<photo>'."\n";
|
|
|
|
print XML '<image>'.$new_file.'</image>'."\n";
|
|
|
|
print XML '<mid>mid_'.$new_file.'</mid>'."\n";
|
|
|
|
print XML '<thumbnail>thm_'.$new_file.'</thumbnail>'."\n";
|
|
|
|
print XML '<order>'.$i.'</order>'."\n";
|
|
|
|
print XML '<caption></caption>'."\n";
|
|
|
|
|
|
|
|
if ($file =~ /.jpg$/i || $file =~ /.jpeg$/i) {
|
|
|
|
$exif = new Image::ExifTool;
|
|
|
|
$exif->ImageInfo($input);
|
|
|
|
print XML '<camera>'.$exif->GetValue("Model").'</camera>'."\n";
|
|
|
|
print XML '<exposurecompensation>'.$exif->GetValue("ExposureCompensation").'</exposurecompensation>'."\n"; # Added in later migration
|
|
|
|
print XML '<shutter>'.$exif->GetValue("ShutterSpeed").'</shutter>'."\n";
|
|
|
|
print XML '<aperture>'.$exif->GetValue("ApertureValue").'</aperture>'."\n";
|
|
|
|
print XML '<focallength>'.$exif->GetValue("FocalLength").'</focallength>'."\n";
|
|
|
|
print XML '<iso>'.$exif->GetValue("ISO").'</iso>'."\n";
|
|
|
|
} else {
|
|
|
|
print XML '<camera></camera>'."\n";
|
|
|
|
print XML '<shutter></shutter>'."\n";
|
|
|
|
print XML '<aperture></aperture>'."\n";
|
|
|
|
print XML '<focallength></focallength>'."\n";
|
|
|
|
print XML '<iso></iso>'."\n";
|
|
|
|
}
|
|
|
|
print XML '</photo>'."\n"; print LOG ".\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print XML '</album>'."\n";
|
|
|
|
|
|
|
|
print LOG "Closing XML.\n";
|
|
|
|
close(XML);
|
|
|
|
|
|
|
|
print LOG "Zipping imgpkg.\n";
|
|
|
|
|
|
|
|
$imgpkg_path = $directory."Photos.imgpkg";
|
|
|
|
print LOG "imgpkg path : $imgpkg_path\n";
|
|
|
|
$zip_files_path = $directory.'temp/';
|
|
|
|
print LOG "zip_files_path : $zip_files_path\n";
|
|
|
|
|
|
|
|
# `zip -df -j -m -T -9 -q $imgpkg_path $zip_files_path`;
|
|
|
|
`zip -mT9qj "$imgpkg_path" "$zip_files_path"*`;
|
|
|
|
|
|
|
|
print LOG "Removing temporary directory.\n";
|
|
|
|
|
|
|
|
rmdir("$newdir");
|
|
|
|
|
|
|
|
print LOG "imgpkg created successfully.\n";
|
|
|
|
print LOG "Image packaging completed.\n";
|