feat(images): automate JPG/JPEG to PNG conversion - Recursively scan directories for JPG and JPEG files - Convert images to PNG using ImageMagick - Preserve original directory structure - Remove
54 lines
1.3 KiB
Bash
Executable File
54 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
###############################################################################
|
|
# Script Name: jpg-to-png.sh
|
|
#
|
|
# Description:
|
|
# Recursively scans the current directory for JPG and JPEG images,
|
|
# converts each image to PNG format using ImageMagick, and removes
|
|
# the original JPG/JPEG file after a successful conversion.
|
|
#
|
|
# The script preserves the original directory structure and creates
|
|
# PNG files alongside the source images.
|
|
#
|
|
# Requirements:
|
|
# - Bash
|
|
# - ImageMagick (convert)
|
|
#
|
|
# Usage:
|
|
# Convert all JPG/JPEG files under the current directory:
|
|
#
|
|
# ./jpg-to-png.sh
|
|
#
|
|
# Example:
|
|
# Before:
|
|
# photo.jpg
|
|
# images/picture.jpeg
|
|
#
|
|
# After:
|
|
# photo.png
|
|
# images/picture.png
|
|
#
|
|
# Notes:
|
|
# - Original JPG/JPEG files are deleted after conversion.
|
|
# - Existing PNG files with the same name may be overwritten.
|
|
# - The script processes files recursively.
|
|
#
|
|
###############################################################################
|
|
|
|
IMG_FOLDER="."
|
|
|
|
# Find all JPG/JPEG files recursively
|
|
IMG_ARR=($(find "${IMG_FOLDER}" -iname '*.jpg' -o -iname '*.jpeg'))
|
|
|
|
for IMG in "${IMG_ARR[@]}"; do
|
|
|
|
echo "Converting: ${IMG}"
|
|
|
|
# Convert JPG/JPEG to PNG
|
|
convert "$IMG" "$(echo "$IMG" | sed 's/\.[jJ][pP][eE]\?[gG]$/.png/')"
|
|
|
|
# Remove original image
|
|
rm "$IMG"
|
|
|
|
done |