mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[png2uri] Changed environment variable from "format" to "PNG2URI_FMT"
and cleaned up indentation.
This commit is contained in:
102
png2uri
102
png2uri
@@ -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)
|
||||
case X$1 in
|
||||
X-f|X--format)
|
||||
shift
|
||||
case x$1 in
|
||||
xpng|xPNG)
|
||||
format=image/png
|
||||
|
||||
case X$1 in
|
||||
Xpng|XPNG)
|
||||
PNG2URI_FMT=image/png
|
||||
;;
|
||||
xjpeg|xJPEG|xjpg|xJPG)
|
||||
format=image/jpeg
|
||||
|
||||
Xjpeg|XJPEG|Xjpg|XJPG)
|
||||
PNG2URI_FMT=image/jpeg
|
||||
;;
|
||||
xbmp|xBMP)
|
||||
format=image/bmp
|
||||
|
||||
Xbmp|XBMP)
|
||||
PNG2URI_FMT=image/bmp
|
||||
;;
|
||||
xgif|xGIF)
|
||||
format=image/gif
|
||||
|
||||
Xgif|XGIF)
|
||||
PNG2URI_FMT=image/gif
|
||||
;;
|
||||
|
||||
*)
|
||||
format=$1
|
||||
PNG2URI_FMT=$1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
;;
|
||||
x-u|x--ur*)
|
||||
uri_only="true"
|
||||
|
||||
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,"
|
||||
|
||||
case X$PNG2URI_URI in
|
||||
Xfalse)
|
||||
echo "data:$PNG2URI_FMT;base64,"
|
||||
uuencode -m ==== | grep -v ====
|
||||
;;
|
||||
false)
|
||||
echo "<img alt=\"PNG\" title=\"PNG\" src=\"data:$format;base64,"
|
||||
|
||||
*)
|
||||
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
|
||||
case X$PNG2URI_FMT in
|
||||
Xunknown)
|
||||
PNG2URI_FMT=image/png
|
||||
extension=`echo $1 | sed "s/.*\.//"`
|
||||
case x$extension in
|
||||
xjpeg|xJPEG|xjpg|xJPG)
|
||||
format=image/jpeg
|
||||
|
||||
case X$extension in
|
||||
Xjpeg|XJPEG|Xjpg|XJPG)
|
||||
PNG2URI_FMT=image/jpeg
|
||||
;;
|
||||
xbmp|xBMP)
|
||||
format=image/bmp
|
||||
|
||||
Xbmp|XBMP)
|
||||
PNG2URI_FMT=image/bmp
|
||||
;;
|
||||
xgif|xGIF)
|
||||
format=image/gif
|
||||
|
||||
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 "\">"
|
||||
;;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user