Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/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 在PS-CS6脚本中获得图像的宽度和高度,而无需打开它_Javascript_Photoshop_Photoshop Script - Fatal编程技术网

Javascript 在PS-CS6脚本中获得图像的宽度和高度,而无需打开它

Javascript 在PS-CS6脚本中获得图像的宽度和高度,而无需打开它,javascript,photoshop,photoshop-script,Javascript,Photoshop,Photoshop Script,我费力地在文档(,)中搜索答案,但找不到任何人。考虑一下,我们有一组来自硬盘中某个文件夹的文件。我们希望根据阵列中文件的尺寸筛选这些文件。这意味着,要筛选两侧(宽度或高度)的图像比某个值高同时也比某个值低。当然我们可以在PS中打开每个文件作为文档,并通过属性app.activeDocument.width或app.activeDocument.height检查每个文件,然后选择最高的一个并匹配它。但它的效率极低,尤其是当我们有数百个文件,但只有少数文件符合条件时。 所以我的问题是:是否有可能在不

我费力地在文档(,)中搜索答案,但找不到任何人。

考虑一下,我们有一组来自硬盘中某个文件夹的文件。我们希望根据阵列中文件的尺寸筛选这些文件。
这意味着,要筛选两侧(宽度或高度)的图像比某个值高同时也比某个值低。

当然我们可以在PS中打开每个文件作为
文档
,并通过属性
app.activeDocument.width
app.activeDocument.height
检查每个文件,然后选择最高的一个并匹配它。但它的效率极低,尤其是当我们有数百个文件,但只有少数文件符合条件时。

所以我的问题是:
是否有可能在不打开图像的情况下检查
宽度
高度
如果不需要安装第三方软件就可以做到这一点,那就太好了。
如果不满足,则无需手动安装(某些单机版)。
即使不满足上述条件,任何解决方案都比没有解决方案好

代码:

var sourceFolder = Folder.selectDialog("Select folder with files to process");

var LowestValueOfSides = 50; // Any arbitrary value

var HighestValueOfSides = 100; // Any arbitrary value

var FilesToProcess = getFilesToProcess(sourceFolder, LowestValueOfSides, HighestValueOfSides);

alert(FilesToProcess);

function getFilesToProcess(sourceFolder, LowestValueOfSides, HighestValueOfSides) {

    sourceFilesUnfiltered = sourceFolder.getFiles();
    var properFilesExtPSfiles = /.(jpg|tif|psd|bmp|gif|png)$/;

    var sourceFilesFilteredPSD = filteringSourceFilesByExtensions(sourceFilesUnfiltered, properFilesExtPSfiles);

    var sourceFilesFilteredByRes = filteringSourceFilesByRes(sourceFilesFilteredPSD, LowestValueOfSides, HighestValueOfSides);

    return sourceFilesFilteredByRes;
}

function filteringSourceFilesByExtensions(sourceFilesUnfiltered, properFilesExtPSfiles) {

    var sourceFilesFiltered = new Array;

    for (var i = 0; i < sourceFilesUnfiltered.length; i++) { 
        if (sourceFilesUnfiltered[i] instanceof File) {

            var sourceFilePathString = sourceFilesUnfiltered[i].toString();

            var sourceFileToMatch = decodeURIComponent(sourceFilePathString);

            if (sourceFileToMatch.match(properFilesExtPSfiles)) {// decodeURIComponent(), to avoid problem when you have special signs in source files

                sourceFilesFiltered.push( File(sourceFilePathString) );
            } 
        } 
    }

    return sourceFilesFiltered;
}

function filteringSourceFilesByRes(sourceFilesFilteredPSD, LowestValueOfSides, HighestValueOfSides) {

    var sourceFilesFilteredByRes = new Array;

    for (var i = 0; i < sourceFilesFilteredPSD.length; i++) {

        var longestSide = getLongestSideValue(sourceFilesFilteredPSD[i]); //   <====== this is function which I have problem

        if ( (longestSide >= LowestValueOfSides) && (longestSide <= HighestValueOfSides)) {
            sourceFilesFilteredByRes.push(sourceFilesFilteredPSD[i]);
        }
    }

    return sourceFilesFilteredByRes;
}

function getLongestSideValue(File) { //   <====== this is function which I have problem

    var FileWidth // <===== I need this value
    var FileHeight // <===== I need this value

    var longestSideValue = Math.max(FileWidth, FileHeight);

    return longestSideValue;
}
var sourceFolder=Folder.selectDialog(“选择包含要处理的文件的文件夹”);
var LowerstValueOfsides=50;//任意值
var HighestValueOfSides=100;//任意值
var FilesToProcess=getFilesToProcess(sourceFolder,最低的sides值,最高的sides值);
警报(FilesToProcess);
函数getFilesToProcess(sourceFolder、最低的sides值、最高的sides值){
SourceFilesUnfilted=sourceFolder.getFiles();
var properFilesExtPSfiles=/(jpg | tif | psd | bmp | gif | png)$/;
var sourceFilesFilteredPSD=filteringSourceFilesByExtensions(sourcefilesfunfiltered,properFilesExtPSfiles);
var sourceFilesFilteredByRes=filteringSourceFilesByRes(sourceFilesFilteredPSD,最低的边值,最高的边值);
返回sourceFilesFilteredByRes;
}
函数过滤器SourceFilesByExtensions(sourceFilesUnfiltered,PropertyFilesExtPSFiles){
var sourceFilesFiltered=新数组;
对于(var i=0;ivar longestSide=getLongestSideValue(sourceFilesFilteredPSD[i]);//=lowerstvalueofsides)和(longestSide不确定您在寻找什么样的答案,因为您似乎想编写Javascript,但不想让Photoshop打开您的图像,因此我想建议您可以使用ImageMagick在终端(命令提示符)中轻松获得所有JPEG/PNG图像的宽度和高度,如下所示:

magick identify -format "%hx%w - %f\n" *.jpg *.png
1936x2592 - iphone.jpg
100x100 - lime.jpg
600x600 - out.jpg
400x400 - paddington.jpg
100x100 - red.jpg
1936x2592 - result-fft.jpg
50x50 - result.jpg
178x178 - 1.png
178x178 - 2.png
请注意,PSD和TIFF文件通常有多个图层,因此您可能需要在其中添加这些类型的图层号:

magick identify -format "%hx%w - %f[%s]\n" *psd *tif
768x1024 - a.psd[0]
768x1024 - a.psd[1]
248x1280 - a.tif[0]

您是否尝试过actualWidth/actualWidth?请参阅上述文章中的actualWidth和actualWidth只是引用openend文档的局部变量,而不是泛型属性。@Lukkar恐怕唯一的选择是使用open(file)以编程方式打开文件,使用.width.value获取其宽度,然后将其关闭。True。Adobe只是没有想到这个用例。File类包含一些属性,但当然不是物理维度。我没有尝试过,但可能是will提供的work@obscure-“Adobe只是没有想到这个用例。”这并不完全正确。请参阅。在某些情况下,“选项是使用open(file)”以编程方式打开文件(特别是对于
.png
bmp
.gif
等格式,如果它们没有通过Adobe应用程序进行处理),但我不同意这是“唯一选项”.Lukkar可能会尝试通过XMP数据包获取维度,如果元数据不存在,则恢复使用
open(file)
。是否可以在Adobe的ExtendedScript中调用Terminal(命令提示符)并向其传递参数?你的意思是这样的吗?它可以工作,但……在我的例子中是“app.system”(“某些Windows命令”)'不起作用。您必须创建bat文件,然后执行[link]()
var bat=new file(“~/Documents/ps_test.bat”);
bat.open('w');
bat.writeln('magick-identify-format“%%hx%%w-%%f\\n”D:\\some path\\file.png“>”D:\\some path\\results.txt”);
bat writeln;
bat.execute();
有关转义字符的其他信息,适用于希望在jsx中创建自己的bat文件的任何人:,