PhotoshopでJavaScriptを使ってまとめてRAW現像する
正確には、RAW現像したことのある(*.xmpファイルがある)写真がたくさんあって、これを全部、WebアルバムにアップロードするためのJPEG画像として出力したかったのです。
PhotoshopをはじめとするAdobe製品はJavaScriptでスクリプトが書けるようなAPIを用意してくれているので、簡単にできました。
app.preferences.rulerUnits = Units.PIXELS; app.preferences.typeUnits = TypeUnits.PIXELS; app.displayDialogs = DialogModes.NO; var jpegOptions = new JPEGSaveOptions(); jpegOptions.embedColorProfile = true; jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE; jpegOptions.matte = MatteType.NONE; jpegOptions.quality = 12; var inputFolder = new Folder("C:\\Users\\arc\\Pictures\\2012-06 Redmond, US\\"); var inputFiles = inputFolder.getFiles("*.ARW"); for (var i = 0; i < inputFiles.length; i ++) { var inputFile = inputFiles[i]; // Resize if needed var inputDocument = app.open(inputFile); if (inputDocument.width.value > inputDocument.height.value) { if (inputDocument.width.value > 2048) inputDocument.resizeImage( 2048, 2048 * inputDocument.height.value / inputDocument.width.value); } else { if (inputDocument.height.value > 2048) inputDocument.resizeImage( 2048 * inputDocument.width.value / inputDocument.height.value, 2048); } // Save var inputFileName = inputFile.fsName; var outputFileName = inputFileName.substr(0, inputFileName.length - 4) + ".jpg"; inputDocument.saveAs(new File(outputFileName), jpegOptions, true); inputDocument.close(SaveOptions.DONOTSAVECHANGES); }
フォルダを指定して、そこから対象となるファイル一覧を取得して、個々のRAWファイルをPhotoshopで開いて、もしサイズが大きければ*1縮小して、拡張子を.jpgに変えて保存しています。RAWにGPSの情報が含まれていたらそれもうまいことJPEGのEXIFに埋め込んでくれるのでとても便利です。
このスクリプトで出力したJPEG画像は加藤 淳のポートフォリオ | junkato.jpにアップロードしてあります。