Last active
September 10, 2018 16:41
-
-
Save actcoment/11c7c3af04c7537e932c5588e369e9c9 to your computer and use it in GitHub Desktop.
ブログ用フォルダ内の画像をいっぺんに横幅640pxに揃えて、元のフォルダの画像をからにするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//for PhotoshopCS3 | |
preferences.rulerUnits = Units.PIXELS; | |
//サムネイルの最大サイズ max pixels | |
maxpx = 640; | |
//サムネイルを保存するフォルダ名。このスクリプト実行時に聞かれるフォルダの下に作成する。 | |
thumbDir = 'thumbnail'; | |
//特定のフォルダ以下のすべてのJPGを開く | |
var dirObj = new Folder("C:/Users/****/Pictures/ブログ用"); | |
var files_jpg = dirObj.getFiles("*.jpg"); | |
var files_png = dirObj.getFiles("*.png"); | |
var savedirObj = new Folder("C:/Users/****/Pictures/blog_img_640"); | |
var saved_jpg = savedirObj.getFiles("*.jpg"); | |
var addednum=saved_jpg.length; | |
var files= files_jpg.concat(files_png); | |
for(var i=0; i<files.length; i++){ | |
//ファイル開く | |
var theDoc = app.open(files[i]); | |
theDoc.changeMode(ChangeMode.RGB); | |
//リサイズする | |
var w = theDoc.width.value; | |
var h = theDoc.height.value; | |
if( w > maxpx){ | |
theDoc.resizeImage(maxpx, h*(maxpx/w), 72, ResampleMethod.BICUBICSHARPER); | |
} | |
//保存する | |
var dObj = new Date(); | |
var y = dObj.getFullYear().toString(); | |
var m = dObj.getMonth() + 1; | |
if(m<10)m="0"+m; | |
var d = dObj.getDate(); | |
if(d<10)d="0"+d; | |
var str=y+m+d; | |
var newDir = new Folder("C:/Users/michiro/Dropbox/EvernoteFolder/blog_img_640/"+str); | |
if(! newDir.exists){ newDir.create();} | |
var num=i+addednum; | |
var newFile = new File(newDir.path +'/'+str+"/"+ str+"_"+num); | |
var jpegopt = new JPEGSaveOptions(); | |
jpegopt.quality = 7; //0(low)~12(high); | |
theDoc.saveAs(newFile, jpegopt, true); | |
//消す | |
//theDoc.close(SaveOptions.DONOTSAVECHANGES); | |
//var file=files[i].remove(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment