乐闻世界logo
搜索文章和话题

How to resize images using terminal on Mac OSX?

1个答案

1

Using the Terminal to adjust image size on Mac OS X is a convenient method, especially when processing multiple files in bulk. Below, I'll explain how to use the command-line tool sips for resizing images.

Step 1: Open Terminal

First, open the Terminal on your Mac. You can do this by typing "Terminal" in Spotlight search or by locating it in the Applications folder.

Step 2: Use the sips Command

On Mac OS X, sips is a powerful built-in command-line tool for image processing. It allows you to adjust image size, change formats, and more.

Command Format for Adjusting Image Size:

The command format for resizing images is:

bash
sips -Z max_size filename

The -Z parameter ensures the image maintains its original aspect ratio during resizing. max_size specifies the maximum width or height (the larger dimension will be scaled to this value, while the other dimension adjusts proportionally).

Example:

Suppose you have an image named example.jpg and want to set its maximum dimension to 800 pixels. Use this command:

bash
sips -Z 800 example.jpg

This adjusts example.jpg to a maximum dimension of 800 pixels while preserving its aspect ratio.

Step 3: Batch Processing Images

For multiple images, leverage terminal loop commands. For instance, to resize all JPEG files in the current directory to a width of 600 pixels, use:

bash
for img in *.jpg; do sips -Z 600 "$img" done

This loop processes all .jpg files in the current directory, resizing them to 600 pixels for the larger dimension (width or height) while maintaining aspect ratio.

Summary

Using the sips command simplifies image resizing in the Mac OS X Terminal. It works efficiently for both individual files and batch processing. This approach helps you manage and adjust your image files more effectively.

2024年6月29日 12:07 回复

你的答案