Photoshop JavaScript将图像和画布调整为特定(非正方形)尺寸 [英] Photoshop JavaScript to resize image and canvas to specific (not square) sizes

查看:109
本文介绍了Photoshop JavaScript将图像和画布调整为特定(非正方形)尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用PhotoShop的JavaScript功能将数百张图像转换为特定的非正方形尺寸(例如320x350px)?

How can I use PhotoShop's JavaScript functionality to convert a set of hundreds of images to a specific, non-square size (e.g. 320x350px)?

推荐答案

在网络上搜索我发现了许多潜在的解决方案,但其中100%转换为正方形.因此,我收集了一些资料,并亲自解决了问题.

Searching the web I've found many potential solutions but 100% of them converted to square sizes. So, I gathered a few and solved the problem myself.

将下面的代码另存为Photoshop \Presets\Scripts文件夹中的.jsx文件.然后,如果要与许多文件一起使用,请执行ACTION.

Save the code below as a .jsx file in your Photoshop \Presets\Scripts folder. Then, make an ACTION if want to use it with many files.

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

这篇关于Photoshop JavaScript将图像和画布调整为特定(非正方形)尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆