Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Photoshop脚本根据像素尺寸调整图像大小(脚本现在无法工作)_Javascript_Photoshop_Photoshop Script - Fatal编程技术网

Javascript Photoshop脚本根据像素尺寸调整图像大小(脚本现在无法工作)

Javascript Photoshop脚本根据像素尺寸调整图像大小(脚本现在无法工作),javascript,photoshop,photoshop-script,Javascript,Photoshop,Photoshop Script,这个脚本是一个更大的Photoshop操作的一部分,我们在Photoshop中编辑产品快照后使用它来处理它们。我最近发现这部分动作(脚本)已经停止正常工作。它应该拍摄任何最长边大于2400px的图像,并将其减少到2400px,忽略任何最长边不大于2400px的图像。但现在,无论图像大小如何,它都在运行,这会放大较小的图像,并在过程中破坏它们 我们最近将Mac客户端从10.8升级到了OS 10.11,在这个过程中,我们还需要运行一些Photoshop更新。我认为这两个因素中的一个或两个都有影响。我

这个脚本是一个更大的Photoshop操作的一部分,我们在Photoshop中编辑产品快照后使用它来处理它们。我最近发现这部分动作(脚本)已经停止正常工作。它应该拍摄任何最长边大于2400px的图像,并将其减少到2400px,忽略任何最长边不大于2400px的图像。但现在,无论图像大小如何,它都在运行,这会放大较小的图像,并在过程中破坏它们

我们最近将Mac客户端从10.8升级到了OS 10.11,在这个过程中,我们还需要运行一些Photoshop更新。我认为这两个因素中的一个或两个都有影响。我们正在运行PhotoshopCS6,这一点没有改变

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

// these are our values for the end result width and height (in pixels) of our image
var fWidth = 2400;
var fHeight = 2400;

// resize. if height > width (portrait-mode) AND height is larger than 2400px -- resize based on height. otherwise, resize based on width only if width is greater than 2400px
if(doc.height > 2400,"px" || doc.width > 2400,"px") {
if (doc.height > doc.width) {
    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
    }
else {
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
    }
}'

如果有任何帮助,我们将不胜感激。

找到了解决方案。感谢Mark Dee对初始参数语法的评论(感谢Mark),我决定简化语法是最好的

我遇到的问题是,当给PS一个数字时,它会根据标尺的当前单位设置单位。因此,如果用户的标尺未设置为正确的单位,脚本将无法工作。以下是我的解决方案:

#target photoshop
// get a reference to the current (active) document and store it in a variable named "doc"
doc = app.activeDocument; 
// setting the ruler unit to pixels
app.preferences.rulerUnits = Units.PIXELS;

// these are our values for the end result width and height (in pixels) of our image
var fWidth = 2400;
var fHeight = 2400;

// resize. if height > width (portrait-mode) AND height is larger than 2400px -- resize based on height. otherwise, resize based on width only if width is greater than 2400px
if(doc.height > 2400 || doc.width > 2400) {
if (doc.height > doc.width) {
    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
    }
else {
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
    }
}
// setting the ruler unit back to inches
app.preferences.rulerUnits = Units.INCHES;

我现在唯一的问题是,它手动将单位设置回英寸,我更希望它只是将单位设置回“以前的单位”,但我不确定如何执行此操作,并且必须进一步深入研究。

您可以获取当前的rulerUnits设置并将其存储在一个变量中,您可以使用该变量进行测试(并更改为)脚本和所需的规则单元。脚本完成后,您可以使用该变量将rulerUnits设置恢复到原来的状态

    // store current unit value
    var userPrefUnits = app.preferences.rulerUnits;

    // change to pixels if not pixels
    if(userPrefUnits !== Units.PIXELS){
       app.preferences.rulerUnits = Units.PIXELS;
    }

    // code based on pixels

    // reset preference if userPrefUnits was not pixels
    if(userPrefUnits !== Units.PIXELS){
       app.preferences.rulerUnits = userPrefUnits;
    }

你的第一个症状看起来很奇怪。
doc.height
.doc.width
是字符串还是数字?如果是数字,请删除
,“px”
。如果是字符串,则执行
2400+“px”
。或者你可以试试
doc.height>UnitValue(2400,“px”)| | doc.width>UnitValue(2400,“px”)
基于你的评论,我决定核化px并简化语法。麻烦的是,当你给PS一个doc.height或doc.width的数字时,它会按照当前在首选项中为标尺设置的单位。我找到了一种方法,用于修复脚本,然后将其恢复。谢谢你指出。请添加一些文字来解释你的答案。不要只是贴一堵代码墙。我为“代码墙”添加了一点介绍:-)