How to use the command 'sips' (with examples)
- Osx
- December 17, 2024
The Apple Scriptable Image Processing System (sips) is a command-line tool designed for image manipulation on macOS. With sips, users can modify image files in various ways, from changing their dimensions to altering their color profiles. This tool is particularly useful for batch processing, as it can handle multiple images at once, ensuring consistency and saving time. Below are specific use cases illustrating how to leverage the sips command, complete with examples.
Use case 1: Specifying an Output Directory
Code:
sips --out path/to/out_dir image_file.ext
Motivation:
One of the frequent requirements in image processing is modifying images without altering the originals, especially when changes may not be reversible or when experimenting with different effects and sizes. By specifying an output directory, users can ensure that the original files remain untouched, allowing for safer processing and easier reversion to the original version if needed.
Explanation:
sips
: Invokes the scriptable image processing system tool.--out path/to/out_dir
: This flag directs sips to save the processed image(s) in the specified output directory. It ensures that the original images are unaffected by the processing.image_file.ext
: Denotes the input image file which you wish to process.
Example Output:
If you moved an image named picture.jpg
to a directory named processed_images
, the file picture.jpg
would remain in its original location unchanged, while the processed image, with modifications done, would be found in the processed_images
directory.
Use case 2: Resampling Image at Specified Size
Code:
sips --resampleHeightWidth 1920 300 image_file.ext
Motivation:
There are instances where specific dimensions are needed for images, such as for web banners or specific thumbnail dimensions. When height and width must match certain numbers for design specifications, this option helps quickly resize images to exact pixel dimensions, albeit at the risk of altering the original aspect ratio.
Explanation:
--resampleHeightWidth
: This flag resizes the image to the specified height and width values.1920 300
: These numbers denote the new height and width in pixels to which you want to resize the image.image_file.ext
: Represents the path to the image file intended for resizing.
Example Output:
An image originally sized at 3840 x 600 pixels resized using the command will have its dimensions changed to 1920 x 300 pixels, possibly distorting the image if the original aspect ratio was different.
Use case 3: Resample Image to Fit Within Maximum Dimensions
Code:
sips --resampleHeightWidthMax 1920 300 image_file.ext
Motivation:
Images often need to maintain aspect ratio while being reduced to fit within a certain space, like creating thumbnails or fitting web page constraints. This command allows the image to be downsized so that either its height or width fits within the specified maximum, preserving the aspect ratio and ensuring no distortion occurs.
Explanation:
--resampleHeightWidthMax
: Resizes the image such that neither its height nor width exceeds the specified maximum dimensions, maintaining the aspect ratio.1920 300
: The maximum allowed height and width dimensions in pixels.image_file.ext
: File path for the image to adjust.
Example Output:
Given an image of size 3840 x 600 pixels resampled with this command, the image may be resized to 960 x 150 pixels, maintaining the aspect ratio, and ensuring it’s within the maximum 1920 x 300 size boundary.
Use case 4: Resample All Images in a Directory for Width
Code:
sips --resampleWidth 960 path/to/images
Motivation:
When managing a batch of images, such as preparing them for a website setup where all images must adhere to a specific width, this command is invaluable. Resizing them all uniformly saves significant manual effort while ensuring consistent presentation and performance considerations, like page load times, are maintained across the site.
Explanation:
--resampleWidth
: Resizes all specified images to the given width.960
: Specifies the new width in pixels.path/to/images
: Directory path containing all images intended for resizing.
Example Output:
Within a directory of images with varying dimensions, each image will be resized such that its width is 960 pixels, while the height will adjust proportionally to preserve the original aspect ratio.
Use case 5: Converting Image from CMYK to RGB
Code:
sips --matchTo "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc" path/to/image.ext path/to/out_dir
Motivation:
The transition between color profiles like CMYK (often used for printing) and RGB (typically used for screens) can be essential when preparing print graphics for digital platforms. This command helps automate that conversion process, ensuring color consistency and accuracy.
Explanation:
--matchTo
: Converts the image’s color profile to the specified ICC profile."/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
: The ICC profile path to which the image should be converted. Here, it specifies conversion to RGB.path/to/image.ext
: The file path for the image being processed.path/to/out_dir
: The directory where the RGB converted image will be saved.
Example Output:
An image originally in CMYK color space is processed and saved as an RGB image in the specified output directory, allowing color accuracy on digital screens.
Use case 6: Removing ColorSync ICC Profile from an Image
Code:
sips --deleteProperty profile --deleteColorManagementProperties path/to/image_file.ext
Motivation:
In situations where ICC profiles cause unwanted color shifts or inconsistencies, removing these profiles can help standardize image colors across different devices and applications. This is particularly helpful in workflows where custom color profiles interfere with target displays or output.
Explanation:
--deleteProperty profile
: Indicates that the ICC profile associated with the image should be removed.--deleteColorManagementProperties
: Further ensures any color management properties tied to the image are deleted.path/to/image_file.ext
: Specifies the image file from which the ICC profile should be removed.
Example Output:
The image file specified will no longer contain any ICC profile information, reducing the file’s embedded metadata size and ensuring consistent display color without additional color management.
Conclusion:
The sips command offers a versatile range of options for image processing on macOS, providing functionality beyond basic software tools, especially with batch processing and command-line automation capabilities. By mastering these commands, users can efficiently manage and process image files to meet both professional and personal needs, maintaining image quality and ensuring desired outcomes.