Created
August 24, 2016 19:18
-
-
Save glsmaxx2015/0235b35a79e7571ed0a9806ffe894fb1 to your computer and use it in GitHub Desktop.
convert image file to png format
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
#! /bin/sh | |
# ############################################################################# | |
NAME_="2png" | |
HTML_="convert to png image format" | |
PURPOSE_="convert image file to png format" | |
SYNOPSIS_="$NAME_ [-vhl] [-r] <file> [file...]" | |
REQUIRES_="standard GNU commands, ImageMagick" | |
VERSION_="1.3" | |
DATE_="1998-11-07; last update: 2004-06-22" | |
AUTHOR_="Dawid Michalczyk <dm@eonworks.com>" | |
URL_="www.comp.eonworks.com" | |
CATEGORY_="gfx" | |
PLATFORM_="Linux" | |
SHELL_="bash" | |
DISTRIBUTE_="yes" | |
# ############################################################################# | |
# This program is distributed under the terms of the GNU General Public License | |
usage () { | |
echo >&2 "$NAME_ $VERSION_ - $PURPOSE_ | |
Usage: $SYNOPSIS_ | |
Requires: $REQUIRES_ | |
Options: | |
-r, remove the input file after conversion | |
-v, verbose | |
-h, usage and options (this help) | |
-l, see this script" | |
exit 1 | |
} | |
# args check | |
[ $# -eq 0 ] && { echo >&2 missing argument, type $NAME_ -h for help; exit 1; } | |
# var init | |
rm_input= | |
verbose= | |
# option and arg handling | |
while getopts vhlr options; do | |
case "$options" in | |
r) rm_input=on ;; | |
v) verbose=on ;; | |
h) usage ;; | |
l) more $0; exit 1 ;; | |
\?) echo invalid argument, type $NAME_ -h for help; exit 1 ;; | |
esac | |
done | |
shift $(( $OPTIND - 1 )) | |
# check if required command is in $PATH variable | |
which mogrify &> /dev/null | |
[[ $? != 0 ]] && { echo >&2 the required ImageMagick \"mogrify\" command \ | |
is not in your PATH variable; exit 1; } | |
# main execution | |
for a in "$@"; do | |
newf=$(echo "${a%.*}".png) | |
if [ -f "$newf" ]; then | |
echo "${NAME_}: skipping converting $a - $newf already exist" && continue | |
else | |
[ -f "$a" ] && mogrify -format png "$a" || continue | |
[[ $verbose ]] && echo "${NAME_}: $a -> $newf" | |
[[ $rm_input ]] && rm -f -- "$a" | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment