Apple的Automator:jpg的压缩设置?

问题描述 投票:9回答:4

当我运行Apple的Automator来简单地剪切大小的图像时,Automator也会降低文件的质量(jpg),并且它们会变得模糊。

我怎么能阻止这个?我可以控制哪些设置?

编辑:

或者是否有其他工具可以完成相同的工作,但不会影响图像质量?

automator
4个回答
6
投票

Automator的“裁剪图像”和“缩放图像”动作没有质量设置 - 正如Automator的情况一样,简单性胜过可配置性。但是,还有另一种方法可以访问CoreImage的图像处理工具,而不需要使用Cocoa编程:Scriptable Image Processing System,它可以使图像处理功能可用于

  1. 壳通过the sips utility。你可以使用它来摆弄最微小的设置,但由于它在处理方面有点神秘,你可能会更好地使用第二种方式,
  2. AppleScript通过Image Events,OS X提供的可编写脚本的无面背景应用程序。有cropscale命令,以及在保存为JPEG时指定压缩级别的选项 save <image> as JPEG with compression level (low|medium|high) 使用“运行AppleScript”操作而不是“裁剪”/“缩放”操作并将图像事件命令包装在tell application "Image Events"块中,您应该进行设置。例如,要将图像缩放到其大小的一半并以最佳质量保存为JPEG,请覆盖原始图像: on run {input, parameters} set output to {} repeat with aPath in input tell application "Image Events" set aPicture to open aPath try scale aPicture by factor 0.5 set end of output to save aPicture as JPEG with compression level low on error errorMessage log errorMessage end try close aPicture end tell end repeat return output -- next action processes edited files. end run - 对于其他比例,相应地调整因子(1 = 100%,。5 = 50%,。25 = 25%等);对于作物,用scale aPicture by factor X替换crop aPicture to {width, height}。 Mac OS X Automation有关于scalecrop使用的很好的教程。

6
投票

如果你想更好地控制JPEG压缩量,kopischke说你必须使用sips实用程序,它可以在shell脚本中使用。以下是您在Automator中的表现:

首先获取文件和压缩设置:

“询问文本”操作不应接受任何输入(右键单击它,选择“忽略输入”)。

确保第一个获取变量值操作不接受任何输入(右键单击它们,选择“忽略输入”),并且第二个获取变量值获取第一个输入。这将创建一个数组,然后将其传递给shell脚本。数组中的第一项是为Automator脚本提供的压缩级别。第二个是脚本将执行sips命令的文件列表。

在Run Shell Script操作顶部的选项中,选择“/ bin / bash”作为Shell并为Pass Input选择“as arguments”。然后粘贴此代码:

itemNumber=0
compressionLevel=0

for file in "$@"
do
    if [ "$itemNumber" = "0" ]; then
        compressionLevel=$file
    else
        echo "Processing $file"
        filename="$file"
        sips -s format jpeg -s formatOptions $compressionLevel "$file" --out "${filename%.*}.jpg"
    fi
    ((itemNumber=itemNumber+1))
done
((itemNumber=itemNumber-1))
osascript -e "tell app \"Automator\" to display dialog \"${itemNumber} Files Converted\" buttons {\"OK\"}"

如果单击底部的“结果”,它将告诉您当前正在处理的文件。有乐趣压缩!


2
投票

Eric的代码非常精彩。可以完成大部分工作。但是如果图像的文件名包含空格,则此工作流程将无法工作。(由于空格会在处理sips时破坏shell脚本。)有一个简单的解决方案:在此工作流程中添加“重命名查找项目”。用“_”或任何你喜欢的东西替换空格。然后,这很好。


0
投票

来自'17的评论

为了避免“空间”问题,更改IFS比重命名更聪明。备份当前IFS并将其更改为\ n only。并在处理循环后恢复原始IFS。

ORG_IFS=$IFS
IFS=$'\n'
for file in $@
do
    ...
done
IFS=$ORG_IFS
© www.soinside.com 2019 - 2024. All rights reserved.