Apple's Automator: compression settings for jpg?

前端 未结 5 1832
滥情空心
滥情空心 2021-02-04 12:53

When I run Apple\'s Automator to simply cut a bunch of images in their size Automator will also reduce the quality of the files (jpg) and they get blurry.

How can I pr

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 13:33

    If you want to have finer control over the amount of JPEG compression, as kopischke said you'll have to use the sips utility, which can be used in a shell script. Here's how you would do that in Automator:

    First get the files and the compression setting:

    Passing files and compression settings to a shell script in Automator

    The Ask for Text action should not accept any input (right-click on it, select "Ignore Input").

    Make sure that the first Get Value of Variable action is not accepting any input (right-click on them, select "Ignore Input"), and that the second Get Value of Variable takes the input from the first. This creates an array that is then passed on to the shell script. The first item in the array is the compression level that was given to the Automator Script. The second is the list of files that the script will do the sips command on.

    In the options on the top of the Run Shell Script action, select "/bin/bash" as the Shell and select "as arguments" for Pass Input. Then paste this code:

    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\"}"
    

    If you click on Results at the bottom, it'll tell you what file it's currently working on. Have fun compressing!

提交回复
热议问题