2013-07-10 61 views

回答

24

在網上搜索我發現了很多潛在的解決方案,但其中100%轉換爲方形尺寸。所以,我收集了一些並自己解決了這個問題。

將以下代碼保存爲您的Photoshop \Presets\Scripts文件夾中的.jsx文件。然後,如果想要將其與多個文件一起使用,請進行操作。

// 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

相關問題