Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple's Automator: compression settings for jpg?

Tags:

automator

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 prevent this? Are there settings that I can take control of?

Edit:

Or are there any other tools that do the same job but without affecting the image quality?

like image 541
Melros Avatar asked May 22 '12 12:05

Melros


People also ask

What type of compression is used for JPG?

JPEG compression. JPEG uses a lossy form of compression based on the discrete cosine transform (DCT). This mathematical operation converts each frame/field of the video source from the spatial (2D) domain into the frequency domain (a.k.a. transform domain).

Can a JPG be compressed?

JPG files can compress considerably to generate tiny file sizes. But as the image quality gets extremely poor with significant compression, it's best to balance the amount of compression with image quality. Because with image compression, you ultimately want as little perceptible image quality loss as possible.


1 Answers

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!

like image 118
Eric Avatar answered Sep 20 '22 03:09

Eric