The command recursively searches for
.cr2
and .dng
files in the current directory and all its subdirectories, converts them to high-quality JPEGs with a resolution of 300 dpi and a color depth of at least 8 bits per channel, and then deletes the original files if the conversion is successful.find . -type
f \( -iname "*.cr2" -o -iname "*.dng" \) | while read -r FILE; do
EXT="${FILE##*.}"; BASE="${FILE%.*}"; NEWFILE="${BASE}-${EXT}.jpg"; sips
-s format jpeg -s formatOptions best -s dpiWidth 300 -s dpiHeight 300
"$FILE" --out "$NEWFILE"; if [ -f "$NEWFILE" ]; then rm "$FILE"; else
echo "Error converting $FILE"; fi; done
Details
find . -type f \( -iname "*.cr2" -o -iname "*.dng" \)
:- Recursively searches for files with
.cr2
or.dng
extensions starting from the current directory (.
).
- Recursively searches for files with
| while read -r FILE; do ... done
:- For each file found, the command within this loop is executed.
EXT="${FILE##*.}"
:- Extracts the file extension (either
cr2
ordng
).
- Extracts the file extension (either
BASE="${FILE%.*}"
:- Removes the file extension to get the base file name.
NEWFILE="${BASE}-${EXT}.jpg"
:- Constructs the new JPEG file name in the format
original-name-cr2.jpg
ororiginal-name-dng.jpg
.
- Constructs the new JPEG file name in the format
sips -s format jpeg -s formatOptions best -s dpiWidth 300 -s dpiHeight 300 "$FILE" --out "$NEWFILE"
:- Converts the file to JPEG format using
sips
:-s format jpeg
: Specifies the output format as JPEG.-s formatOptions best
: Sets the JPEG quality to the best.-s dpiWidth 300 -s dpiHeight 300
: Sets the resolution to 300 dpi."$FILE"
: Specifies the input file.--out "$NEWFILE"
: Specifies the output file with the new name.
- Converts the file to JPEG format using
if [ -f "$NEWFILE" ]; then rm "$FILE"; else echo "Error converting $FILE"; fi
:- Checks if the new JPEG file was successfully created:
- If the new file exists, deletes the original file.
- If the new file does not exist, outputs an error message indicating the conversion failed.
- Checks if the new JPEG file was successfully created:
No hay comentarios:
Publicar un comentario
Escribe tu comentario