2013-07-10 3 views
4

PhotoShop의 JavaScript 기능을 사용하여 수백 세트의 이미지를 정사각형이 아닌 특정 크기 (예 : 320x350 픽셀)로 변환하려면 어떻게해야합니까?이미지와 캔버스를 크기가 정사각형이 아닌 특정 크기로 리사이즈하는 JavaScript 포토샵

+1

당신은/(종료 투표 할 수 있습니다 또는 사람) 미래 : 다른 사람들을 도울 수있는 관련 키워드를 포함하여 다른 사람이 물어 보는 질문을 할 필요가 – lifetimes

답변

24

웹 검색 많은 잠재적 인 솔루션을 찾았지만 100 %는 정사각형 크기로 변환되었습니다. 그래서 몇 가지를 모아서 문제를 직접 풀었습니다.

아래의 코드를 .jsx 파일로 Photoshop \Presets\Scripts 폴더에 저장하십시오. 그런 다음 많은 파일과 함께 사용하려면 ACTION을 만드십시오. 당신이 답을 모르는 것처럼

// get a reference to the current (active) document and store it in a variable named "doc" 
doc = app.activeDocument; 

// change the color mode to RGB. Important for resizing GIFs with indexed colors, to get better results 
doc.changeMode(ChangeMode.RGB); 

// these are our values for the END RESULT width and height (in pixels) of our image 
var fWidth = 320; 
var fHeight = 350; 

// do the resizing. if height > width (portrait-mode) resize based on height. otherwise, resize based on width 
if (doc.height > doc.width) { 
    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC); 
} 
else { 
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC); 
} 

// Makes the default background white 
var white = new SolidColor(); 
white.rgb.hexValue = "FFFFFF"; 
app.backgroundColor = white; 

// Convert the canvas size as informed above for the END RESULT 
app.activeDocument.resizeCanvas(UnitValue(fWidth,"px"),UnitValue(fHeight,"px")); 

// our web export options 
var options = new ExportOptionsSaveForWeb(); 
options.quality = 70; 
options.format = SaveDocumentType.JPEG; 
options.optimized = true; 

var newName = 'web-'+doc.name+'.jpg'; 

doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options); 
+0

어디 대부분의 코드가 있습니다. https://coffeeshopped.com/2008/11/conditional-image-resizing-with-photoshop-and-javascript – tibelchior

+2

공유해 주셔서 감사합니다. – Jarrod

관련 문제