Last active
March 23, 2024 16:03
-
-
Save betsalel-williamson/118cf18b398534c625e721674c26d099 to your computer and use it in GitHub Desktop.
Script to convert PNG image to white
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
## Converts png image to white using the "convert" utility from imagemagick | |
# | |
# MIT No Attribution | |
# | |
# Copyright 2024 Betsalel "Saul" Williamson | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of this | |
# software and associated documentation files (the "Software"), to deal in the Software | |
# without restriction, including without limitation the rights to use, copy, modify, | |
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | |
# permit persons to whom the Software is furnished to do so. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
####################################################################################### | |
# get filename and extension | |
base_filename=$(basename -- "$1") | |
filename="${base_filename%.*}" | |
# get extension | |
extension="${base_filename##*.}" | |
extension_upper=$(echo -n ${extension} | tr '[:lower:]' '[:upper:]') | |
case $extension_upper in | |
PNG) | |
convert "$1" -fill white -colorize 100 "${filename}_white.png" | |
;; | |
*) | |
>&2 echo "ERROR: File must have png extension" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment