diff options
author | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2012-07-05 06:51:29 -0500 |
---|---|---|
committer | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2012-07-05 06:51:29 -0500 |
commit | 35fbb6e6de480daf33b74ff64eb7b277ddf9b954 (patch) | |
tree | 30a71b3227fb617e2b1a671a77a3ee0a9d3f8c6c | |
parent | 9947a5f360721238a1fb9933cf5096fa74037283 (diff) | |
download | libpng-png2uri-1.0.3.tar.gz |
[png2uri] Changed environment variable from "format" to "PNG2URI_FMT"png2uri-1.0.3
and cleaned up indentation.
-rwxr-xr-x | png2uri | 144 | ||||
-rw-r--r-- | png2uri-README.txt | 10 |
2 files changed, 87 insertions, 67 deletions
@@ -1,6 +1,6 @@ #!/bin/sh # -# png2uri version 1.0.2, July 4, 2012. +# png2uri version 1.0.3, July 5, 2012. # # NO COPYRIGHT RIGHTS ARE CLAIMED TO THIS SOFTWARE. # @@ -23,8 +23,8 @@ # png2uri is a command-line application that creates an HTML "img" tag on # standard output containing a data URI in accordance with RFC-2397, from # a PNG file or from a PNG datastream received from standard input. -# Other formats besides the default, PNG, are supported, via the "-f or -# --format option or, if that option was not supplied, by inspection of the +# Other formats besides the default, PNG, are supported, via the "-f" or +# "--format" option or, if that option was not supplied, by inspection of the # filename extension. # # Usage: png2uri [-f type|--format type] [-u|--uri_only] [file] @@ -44,86 +44,100 @@ # to encode in base64 according to RFC-3548, and a working "sed". # # If you prefer a web-based converter or a java application, this isn't -# it. Use your search engine and look for "png data uri" to find one. +# it. Use your search engine and look for "data uri" to find one. # -uri_only="false" -format="unknown" +PNG2URI_URI="true" +PNG2URI_FMT="unknown" while true do -case x$1 in - x-f|x--format) - shift - case x$1 in - xpng|xPNG) - format=image/png - ;; - xjpeg|xJPEG|xjpg|xJPG) - format=image/jpeg - ;; - xbmp|xBMP) - format=image/bmp - ;; - xgif|xGIF) - format=image/gif - ;; - *) - format=$1 - ;; - esac - shift - ;; - x-u|x--ur*) - uri_only="true" +case X$1 in + X-f|X--format) + shift + + case X$1 in + Xpng|XPNG) + PNG2URI_FMT=image/png + ;; + + Xjpeg|XJPEG|Xjpg|XJPG) + PNG2URI_FMT=image/jpeg + ;; + + Xbmp|XBMP) + PNG2URI_FMT=image/bmp + ;; + + Xgif|XGIF) + PNG2URI_FMT=image/gif + ;; + + *) + PNG2URI_FMT=$1 + ;; + esac + shift + ;; + + X-u|X--ur*) + PNG2URI_URI="false" shift ;; - x) + + X) # Convert standard input. - case $format in - unknown) - format=image/png - ;; + case X$PNG2URI_FMT in + Xunknown) + PNG2URI_FMT=image/png + ;; esac - case $uri_only in - true) - echo "data:$format;base64," - uuencode -m ==== | grep -v ==== - ;; - false) - echo "<img alt=\"PNG\" title=\"PNG\" src=\"data:$format;base64," - uuencode -m ==== | grep -v ==== - echo "\">" - ;; + + case X$PNG2URI_URI in + Xfalse) + echo "data:$PNG2URI_FMT;base64," + uuencode -m ==== | grep -v ==== + ;; + + *) + echo "<img alt=\"PNG\" title=\"PNG\" src=\"data:$PNG2URI_FMT;base64," + uuencode -m ==== | grep -v ==== + echo "\">" + ;; esac exit ;; + *) # Convert the named file. - case $format in - unknown) - format=image/png - extension=`echo $1 | sed "s/.*\.//"` - case x$extension in - xjpeg|xJPEG|xjpg|xJPG) - format=image/jpeg - ;; - xbmp|xBMP) - format=image/bmp - ;; - xgif|xGIF) - format=image/gif - ;; + case X$PNG2URI_FMT in + Xunknown) + PNG2URI_FMT=image/png + extension=`echo $1 | sed "s/.*\.//"` + + case X$extension in + Xjpeg|XJPEG|Xjpg|XJPG) + PNG2URI_FMT=image/jpeg + ;; + + Xbmp|XBMP) + PNG2URI_FMT=image/bmp + ;; + + Xgif|XGIF) + PNG2URI_FMT=image/gif + ;; esac - ;; + ;; esac - case $uri_only in - true) - echo "data:$format;base64," + + case X$PNG2URI_URI in + Xfalse) + echo "data:$PNG2URI_FMT;base64," uuencode -m $1 ==== | grep -v ==== ;; - false) - echo "<img alt=\"$1\" title=\"$1\" src=\"data:$format;base64," + *) + echo "<img alt=\"$1\" title=\"$1\" src=\"data:$PNG2URI_FMT;base64," uuencode -m $1 ==== | grep -v ==== echo "\">" ;; diff --git a/png2uri-README.txt b/png2uri-README.txt index f9f4f7d12..19e48239a 100644 --- a/png2uri-README.txt +++ b/png2uri-README.txt @@ -21,8 +21,8 @@ png2uri is a command-line application that creates an HTML "img" tag on standard output containing a data URI, from a PNG file or from standard - input. Other formats besides the default, PNG, are supported, via the "-f - or --format option or, if that option was not supplied, by inspection of + input. Other formats besides the default, PNG, are supported, via the "-f" + or "--format" option or, if that option was not supplied, by inspection of the filename extension. Usage: png2uri [-f format|--format format] [-u|--uri_only] [file] @@ -93,6 +93,12 @@ Implemented "-f TYPE" and "--format TYPE" option. + Version 1.0.3, July 5, 2012: + + Changed environment variable "format" to PNG2URI_FMT reduce possibility` + of name conflict, and changed "uri_only" to PNG2URI_URI. Fixed some + indentation. + TO DO 1. Test on various platforms. The following have been tried |