You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
4 years ago
|
#!/bin/bash
|
||
|
|
||
|
# Build instructions:
|
||
|
# https://medium.com/@eplt/5-minutes-to-install-imagemagick-with-heic-support-on-ubuntu-18-04-digitalocean-fe2d09dcef1
|
||
|
# Command:
|
||
|
# https://zwbetz.com/convert-heic-images-to-jpg/
|
||
|
|
||
|
# The folder with the files you want to convert
|
||
|
directory=/path/to/your/uploads
|
||
|
# Set to 0 to delete the original .heic files after they are converted
|
||
|
keeporiginals=1
|
||
|
# Set to 0 for PNG (much larger file size)
|
||
|
saveasjpg=1
|
||
|
|
||
|
# Make sure the mogrify command is available
|
||
|
which mogrify > /dev/null
|
||
|
[ $? -eq 1 ] && echo "Unable to run the mogrify command. Please follow the build and installation instructions at the top of the script to install the program on your system." && exit
|
||
|
|
||
|
# Change into the folder with our images
|
||
|
cd "$directory"
|
||
|
|
||
|
# Loop over all the .heic files in the folder
|
||
|
for heic in *.heic; do
|
||
|
# Drop the .heic extension and append .jpg instead
|
||
|
if [ $saveasjpg -eq 0 ]; then
|
||
|
img=`echo "$heic" | rev | cut -d. -f2- | rev`.png
|
||
|
else
|
||
|
img=`echo "$heic" | rev | cut -d. -f2- | rev`.jpg
|
||
|
fi
|
||
|
# If the file we are going to make does not exist, run the command to convert it
|
||
|
if [ $saveasjpg -eq 0 ]; then
|
||
|
[ -f "$img" ] || /usr/local/bin/mogrify -format png "$heic"
|
||
|
else
|
||
|
[ -f "$img" ] || /usr/local/bin/mogrify -format jpg "$heic"
|
||
|
fi
|
||
|
# If we don't want the originals, give them the axe
|
||
|
[ $keeporiginals -eq 0 ] && rm "$heic"
|
||
|
done
|