<分区>
如何使用 PhotoShop 的 JavaScript 功能将一组数百张图像转换为特定的非方形尺寸(例如 320x350 像素)?
<分区>
如何使用 PhotoShop 的 JavaScript 功能将一组数百张图像转换为特定的非方形尺寸(例如 320x350 像素)?
最佳答案
我在网上搜索了很多可能的解决方案,但其中 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);
关于javascript - Photoshop JavaScript 将图像和 Canvas 调整为特定(非正方形)大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17580923/
相关文章:
javascript - 如何创建中间有孔的 Canvas html5 剪切区域?
python - 如果我使用 grid(),为什么当我调整窗口大小时小部件不缩放?
.net - WPF Datagrid 模板删除了调整列大小的能力
javascript - image.src 到大图像在加载时卡住
c# - Xamarin 表单以编程方式扩展 ListView 高度
javascript - 负循环 while 循环是无限循环 - 尝试在没有操作数的情况下添加
Javascript DOM 操作,每次点击创建一个新的 li 元素