Update smma/imagemagick.md
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
Certainly! Here is a simplified `README.md` that provides clear instructions for setting up the project, cloning the repository, and updating the `zsh` configuration for the alias.
|
||||
|
||||
### README.md
|
||||
|
||||
```markdown
|
||||
# Image Converter
|
||||
|
||||
This project provides a script to convert WEBP and HEIC images to PNG and JPG formats using ImageMagick.
|
||||
@@ -11,27 +6,41 @@ This project provides a script to convert WEBP and HEIC images to PNG and JPG fo
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Make sure you have ImageMagick installed. You can check if it's installed by running:
|
||||
#### Install Homebrew
|
||||
|
||||
To install Homebrew, run the following command:
|
||||
|
||||
```bash
|
||||
convert -version
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
```
|
||||
|
||||
If not installed, you can install it using:
|
||||
After installation, add Homebrew to your PATH:
|
||||
|
||||
- **macOS**:
|
||||
- For **zsh** (default for macOS Catalina and later):
|
||||
```bash
|
||||
brew install imagemagick
|
||||
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
|
||||
source ~/.zshrc
|
||||
```
|
||||
|
||||
- **Ubuntu**:
|
||||
- For **bash**:
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install imagemagick
|
||||
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
|
||||
source ~/.bash_profile
|
||||
```
|
||||
|
||||
- **Windows**:
|
||||
Download and install from the [ImageMagick website](https://imagemagick.org/script/download.php).
|
||||
#### Install ImageMagick
|
||||
|
||||
With Homebrew installed, run the following command to install ImageMagick:
|
||||
|
||||
```bash
|
||||
brew install imagemagick
|
||||
```
|
||||
|
||||
Verify the installation by checking the version:
|
||||
|
||||
```bash
|
||||
magick --version
|
||||
```
|
||||
|
||||
### Project Setup
|
||||
|
||||
@@ -54,7 +63,7 @@ If not installed, you can install it using:
|
||||
|
||||
Replace `~/path_to_your_script_directory` with the actual path where you cloned the repository.
|
||||
|
||||
## Usage
|
||||
### Usage
|
||||
|
||||
To convert a WEBP or HEIC file to PNG and JPG, use the following command:
|
||||
|
||||
@@ -69,151 +78,102 @@ convert filename.heic
|
||||
```
|
||||
|
||||
The converted files will be saved in `~/Pictures/Converted`.
|
||||
|
||||
### Maintenance Commands
|
||||
|
||||
Keep Homebrew and its packages up-to-date with the following commands:
|
||||
|
||||
- **Update Homebrew**:
|
||||
```bash
|
||||
brew update
|
||||
```
|
||||
|
||||
- **Upgrade installed packages**:
|
||||
```bash
|
||||
brew upgrade
|
||||
```
|
||||
|
||||
- **Cleanup old versions**:
|
||||
```bash
|
||||
brew cleanup
|
||||
```
|
||||
|
||||
## Complete Project Code
|
||||
|
||||
### Project Directory Structure
|
||||
|
||||
```
|
||||
image-converter/
|
||||
├── convert_images.sh
|
||||
├── README.md
|
||||
└── .gitignore
|
||||
```
|
||||
|
||||
### Complete Project Code
|
||||
### convert_images.sh
|
||||
|
||||
1. **Project Directory Structure**:
|
||||
```
|
||||
image-converter/
|
||||
├── convert_images.sh
|
||||
├── README.md
|
||||
└── .gitignore
|
||||
```
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
2. **convert_images.sh**:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Check if the magick command is available
|
||||
if ! command -v magick &> /dev/null; then
|
||||
echo "ImageMagick is not installed or not in your PATH."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the magick command is available
|
||||
if ! command -v magick &> /dev/null; then
|
||||
echo "ImageMagick is not installed or not in your PATH."
|
||||
exit 1
|
||||
fi
|
||||
# Get the input file from the command line argument
|
||||
input_file=$1
|
||||
|
||||
# Get the input file from the command line argument
|
||||
input_file=$1
|
||||
# Check if input file is provided
|
||||
if [ -z "$input_file" ]; then
|
||||
echo "Error: No input file specified. Usage: convert file1.webp or convert file1.heic"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if input file is provided
|
||||
if [ -z "$input_file" ]; then
|
||||
echo "Error: No input file specified. Usage: convert file1.webp or convert file1.heic"
|
||||
exit 1
|
||||
fi
|
||||
# Extract the base name and extension of the input file
|
||||
base_name=$(basename "$input_file" | cut -d. -f1)
|
||||
extension=$(basename "$input_file" | cut -d. -f2)
|
||||
|
||||
# Extract the base name and extension of the input file
|
||||
base_name=$(basename "$input_file" | cut -d. -f1)
|
||||
extension=$(basename "$input_file" | cut -d. -f2)
|
||||
# Define the output directory
|
||||
output_dir="$HOME/Pictures/Converted"
|
||||
|
||||
# Define the output directory
|
||||
output_dir="$HOME/Pictures/Converted"
|
||||
# Check if the output directory exists, create if it does not
|
||||
if [ ! -d "$output_dir" ]; then
|
||||
mkdir -p "$output_dir"
|
||||
fi
|
||||
|
||||
# Check if the output directory exists, create if it does not
|
||||
if [ ! -d "$output_dir" ]; then
|
||||
mkdir -p "$output_dir"
|
||||
fi
|
||||
# Function to convert images
|
||||
convert_images() {
|
||||
local input_file=$1
|
||||
local base_name=$2
|
||||
local output_dir=$3
|
||||
|
||||
# Function to convert images
|
||||
convert_images() {
|
||||
local input_file=$1
|
||||
local base_name=$2
|
||||
local output_dir=$3
|
||||
# Convert to PNG
|
||||
magick "$input_file" "$output_dir/${base_name}.png"
|
||||
echo "Converted $input_file to $output_dir/${base_name}.png"
|
||||
|
||||
# Convert to PNG
|
||||
magick "$input_file" "$output_dir/${base_name}.png"
|
||||
echo "Converted $input_file to $output_dir/${base_name}.png"
|
||||
# Convert to JPG
|
||||
magick "$input_file" "$output_dir/${base_name}.jpg"
|
||||
echo "Converted $input_file to $output_dir/${base_name}.jpg"
|
||||
}
|
||||
|
||||
# Convert to JPG
|
||||
magick "$input_file" "$output_dir/${base_name}.jpg"
|
||||
echo "Converted $input_file to $output_dir/${base_name}.jpg"
|
||||
}
|
||||
# Check the file extension and convert if it is .webp or .heic
|
||||
if [ "$extension" = "webp" ] || [ "$extension" = "heic" ]; then
|
||||
convert_images "$input_file" "$base_name" "$output_dir"
|
||||
else
|
||||
echo "Error: The file must be either .webp or .heic."
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
|
||||
# Check the file extension and convert if it is .webp or .heic
|
||||
if [ "$extension" = "webp" ] || [ "$extension" = "heic" ]; then
|
||||
convert_images "$input_file" "$base_name" "$output_dir"
|
||||
else
|
||||
echo "Error: The file must be either .webp or .heic."
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
### .gitignore
|
||||
|
||||
3. **.gitignore**:
|
||||
```gitignore
|
||||
# Ignore log files and temp files
|
||||
*.log
|
||||
*.tmp
|
||||
```
|
||||
```gitignore
|
||||
# Ignore log files and temp files
|
||||
*.log
|
||||
*.tmp
|
||||
```
|
||||
|
||||
4. **README.md**:
|
||||
```markdown
|
||||
# Image Converter
|
||||
|
||||
This project provides a script to convert WEBP and HEIC images to PNG and JPG formats using ImageMagick.
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Make sure you have ImageMagick installed. You can check if it's installed by running:
|
||||
|
||||
```bash
|
||||
convert -version
|
||||
```
|
||||
|
||||
If not installed, you can install it using:
|
||||
|
||||
- **macOS**:
|
||||
```bash
|
||||
brew install imagemagick
|
||||
```
|
||||
|
||||
- **Ubuntu**:
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install imagemagick
|
||||
```
|
||||
|
||||
- **Windows**:
|
||||
Download and install from the [ImageMagick website](https://imagemagick.org/script/download.php).
|
||||
|
||||
### Project Setup
|
||||
|
||||
1. **Clone the repository**:
|
||||
```bash
|
||||
git clone https://github.com/yourusername/image-converter.git
|
||||
cd image-converter
|
||||
```
|
||||
|
||||
2. **Make the script executable**:
|
||||
```bash
|
||||
chmod +x convert_images.sh
|
||||
```
|
||||
|
||||
3. **Add an alias to your shell configuration file**:
|
||||
```bash
|
||||
echo "alias convert='~/path_to_your_script_directory/convert_images.sh'" >> ~/.zshrc
|
||||
source ~/.zshrc
|
||||
```
|
||||
|
||||
Replace `~/path_to_your_script_directory` with the actual path where you cloned the repository.
|
||||
|
||||
## Usage
|
||||
|
||||
To convert a WEBP or HEIC file to PNG and JPG, use the following command:
|
||||
|
||||
```bash
|
||||
convert filename.webp
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
convert filename.heic
|
||||
```
|
||||
|
||||
The converted files will be saved in `~/Pictures/Converted`.
|
||||
```
|
||||
|
||||
### Final Steps
|
||||
## Final Steps
|
||||
|
||||
1. **Initialize Git Repository**:
|
||||
```bash
|
||||
@@ -230,51 +190,4 @@ The converted files will be saved in `~/Pictures/Converted`.
|
||||
git remote add origin https://github.com/yourusername/image-converter.git
|
||||
git branch -M main
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
Now, anyone can clone your repository and follow the instructions in the `README.md` to set up and use the image conversion script.
|
||||
|
||||
---
|
||||
|
||||
# Install Homebrew
|
||||
```bash
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
```
|
||||
|
||||
# Update your PATH
|
||||
```bash
|
||||
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
|
||||
```
|
||||
# Update your shell
|
||||
```bash
|
||||
source ~/.zshrc
|
||||
```
|
||||
|
||||
# Install ImageMagick
|
||||
```bash
|
||||
brew install imagemagick
|
||||
```
|
||||
|
||||
# Verify the installation
|
||||
```bash
|
||||
magick --version
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Keep Homebrew up-to-date
|
||||
|
||||
# Update Homebrew
|
||||
```bash
|
||||
brew update
|
||||
```
|
||||
|
||||
# Upgrade installed packages
|
||||
```bash
|
||||
brew upgrade
|
||||
```
|
||||
|
||||
# Cleanup old versions
|
||||
```bash
|
||||
brew cleanup
|
||||
```
|
||||
```
|
||||
Reference in New Issue
Block a user