Added HEIC conversion script.

master
parent 3531169e34
commit d9f3d89c04

@ -1,3 +1,8 @@
### Random scripts that I have written for various tasks! ### Random scripts that I have written for various tasks!
## Bash
**convertHEICtoJPG.sh**
This script will convert your HEIC files (a format Apple saves photos with) to JPGs. Flip saveasjpg at the top to save as PNG instead. This will result in much larger file sizes. Set keeporiginals to 0 to delete the HEIC files after they're converted. The HEIC files are saved kept around by default. For best results set this up as a cron job.
more to come more to come

@ -0,0 +1,38 @@
#!/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
Loading…
Cancel
Save