Update docs/random_docs/Image.md

This commit is contained in:
2024-01-26 02:01:30 +00:00
parent 1ed8871d4d
commit b54da155e9

View File

@@ -1,39 +1,53 @@
# Image Resizing on Mac with ImageMagick via Homebrew # Reducing Image File Size on Mac with ImageMagick
This guide provides steps to install ImageMagick using Homebrew and resize an image on a Mac. This guide provides instructions on how to use ImageMagick to reduce the file size of an image on a Mac, aiming for a target file size of 2MB or less.
## Installing ImageMagick ## Prerequisites
1. **Open Terminal:** You can find Terminal in Applications under Utilities or use Spotlight to search for it. Ensure that ImageMagick is installed on your Mac. If not, follow the installation guide below:
2. **Install Homebrew:** If you don't have Homebrew installed, execute the following command in Terminal: 1. **Open Terminal:**
- Terminal can be found in Applications under Utilities or accessed using Spotlight.
2. **Install Homebrew:** (Skip if already installed)
- Run the following command in Terminal to install Homebrew:
```bash ```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
``` ```
3. **Install ImageMagick:** Once Homebrew is installed, run this command to install ImageMagick:
3. **Install ImageMagick:**
- With Homebrew installed, execute this command to install ImageMagick:
```bash ```bash
brew install imagemagick brew install imagemagick
``` ```
## Resizing an Image ## Reducing Image File Size
1. **Navigate to Image Folder:** Change the directory to where your image is located. 1. **Navigate to Image Folder:**
- Change to the directory where your image is stored.
```bash ```bash
cd /path/to/your/image/directory cd /path/to/your/image/directory
``` ```
2. **Resize the Image:** Use the `convert` command from ImageMagick to resize the image. For example, to resize an image named `original.jpg` to a width of 600 pixels while keeping the aspect ratio, use: 2. **Reduce Image File Size:**
- **Option 1: Adjust Quality**
- Lower the quality to reduce file size. Start with a value like 85 and adjust if necessary.
```bash
convert original.jpg -quality 85 compressed.jpg
```
- **Option 2: Resize Image**
- If the image dimensions are large, resizing can help reduce file size.
```bash
convert original.jpg -resize 50% compressed.jpg
```
- Replace `original.jpg` with your image's filename and `compressed.jpg` with your desired new filename.
```bash 3. **Verify File Size:**
convert original.jpg -resize 600x resized.jpg - Check the size of `compressed.jpg`. If it's over 2MB, adjust the quality or resize percentage and repeat the process.
```
This will create a new resized image named `resized.jpg` in the same directory. 4. **Replace Original Image (Optional):**
- To replace the original image, use the same name for the output file in the command.
## Notes ## Conclusion
- The `600x` in the resize command specifies the width in pixels. The height will be adjusted automatically to maintain the aspect ratio. By adjusting the quality or resizing the image, you can effectively reduce its file size to meet specific requirements, such as a maximum of 2MB, using ImageMagick on a Mac.
- If you want to overwrite the original image, use the same name for the output file.
- For more advanced options, refer to the ImageMagick documentation or use `man convert` in Terminal to see the manual.
This guide should help you install ImageMagick using Homebrew and resize images easily on your Mac.