feat(images): add JPG to PNG conversion utility
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
This commit is contained in:
1 parent
aa48304220
commit
2c2bf379a8
2 files changed
+54
-11
No files matched your search
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/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
|
||||
Reference in new issue
Block a user