Caution – Do not edit unless you know what you are doing!
#! /usr/bin/perl# ==================================================================# ** Date: 2012-06-14 **# ** Author:- Nicholas:~ Wikipedia: [[en:User:Nichalp]] **# ** Filename:- csv_creator.pl **# ** Licence:- Published under the GPLv3 licence **# ** Revision:- 1.0.2 **# ** Purpose: Scan all .JPG files in a directory, then read **# ** corresponding Exif information, and then list **# ** them in a CSV file **# ** URL: http://commons.wikimedia.org/wiki/User:Nichalp/Upload_script# ================================================================== usestrict;usewarnings;useutf8;useImage::ExifToolqw(:Public);#Declaring variablesmy$exifTool=newImage::ExifTool;my$file;my$info;my@files;my($author,$date,$aperture,$shutter,$iso,$camera_model,$lens);# Creating the CSV fileopen(UPLOAD,">upload.csv")ordie"Could not write file.\n";# Opening the directoryopendir(DIR,".");# Selecting only JPG file types@files=grep(/\.jpe?g$/i,readdir(DIR));closedir(DIR);# Printing headersprintUPLOAD'"Current name","New name","Description lang","Description","Date","Author name","Permissions","Category1","Category2","Category3","Category4","Category5","Xform","Coordinate type","Lat deg","Lat min","Lat sec","Lat Ref","Long deg","Long min","Long sec","Long Ref","Type","Scale","Region","Heading","Source","Altitude","Other versions 1","Other versions 2","Description lang 2","Description 2","Description lang 3","Description 3","Embed exif?","Caption","Country","State","Place","Website","Keywords","Camera info?","Camera Model","Aperture","Shutter","Film","ISO","Lens","Flickr?","Flickr URL","Flickr image title","Flickr photographer URL","Flickr photographer location","Other information"',"\n";foreach$file(@files){$info=$exifTool->ImageInfo($file);my$rotation=$exifTool->GetValue('Orientation','ValueConv');$info=$exifTool->ImageInfo($file);$date=$$info{DateTimeOriginal};$camera_model=$$info{Model};$aperture=$$info{ApertureValue};$iso=$$info{ISO};$lens=$$info{Lens};$shutter=$$info{ShutterSpeedValue};#printing values printUPLOAD"\"$file\"";printUPLOAD',,,,';if(defined$date)#Checking for null values{printUPLOAD"\"$date\"";}else{printUPLOAD',';};printUPLOAD',,,,,,,,';if(defined$rotation){printUPLOAD"\"$rotation\"";}else{printUPLOAD',';};printUPLOAD',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,';if(defined$camera_model){printUPLOAD"\"$camera_model\"";}else{printUPLOAD',';};printUPLOAD',';if(defined$aperture){printUPLOAD"\"$aperture\""}else{printUPLOAD',';};printUPLOAD',';if(defined$shutter){printUPLOAD"\"'$shutter\"";}#The leading single quote is to prevent spreadsheets from auto-formatting as a date. We will remove it later. else{printUPLOAD',';};printUPLOAD',';printUPLOAD"Digital".',';if(defined$iso){printUPLOAD"\"$iso\"".','}else{printUPLOAD',';};if(defined$lens){printUPLOAD"\"$lens\""}else{printUPLOAD',';};printUPLOAD',,,,,,',"\n";}print"upload.csv successfully created!\n";close(UPLOAD);__END__