mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[png2uri] Version 1.0.5, July 7, 2012: Eliminated use of "uname"
and use the return of "base64" and "uuencode" to select the workable one (checking "base64" first); suggested by John Bowler. Added a check for too many arguments, also a JB suggestion. Accept output filename as an optional final argument.
This commit is contained in:
83
png2uri
83
png2uri
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# png2uri version 1.0.4, July 6, 2012.
|
# png2uri version 1.0.5, July 7, 2012.
|
||||||
#
|
#
|
||||||
# NO COPYRIGHT RIGHTS ARE CLAIMED TO THIS SOFTWARE.
|
# NO COPYRIGHT RIGHTS ARE CLAIMED TO THIS SOFTWARE.
|
||||||
#
|
#
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
# file. None of the people below claim any rights with regard to the
|
# file. None of the people below claim any rights with regard to the
|
||||||
# contents of this file.
|
# contents of this file.
|
||||||
#
|
#
|
||||||
# Glenn Randers-Pehrson <glennrp@users.sourceforge.net>
|
# Glenn Randers-Pehrson <glennrp at users.sourceforge.net> is the author.
|
||||||
|
# John Bowler <jbower at acm.org> contributed some useful suggestions.
|
||||||
#
|
#
|
||||||
# png2uri is a command-line application that creates an HTML "img" tag on
|
# 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
|
# standard output containing a data URI in accordance with RFC-2397, from
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
# "--format" option or, if that option was not supplied, by inspection of the
|
# "--format" option or, if that option was not supplied, by inspection of the
|
||||||
# filename extension.
|
# filename extension.
|
||||||
#
|
#
|
||||||
# Usage: png2uri [-f type|--format type] [-u|--uri_only] [file]
|
# Usage: png2uri [-f type|--format type] [-u|--uri_only] [infile [outfile]]
|
||||||
#
|
#
|
||||||
# options: -f|--format TYPE:
|
# options: -f|--format TYPE:
|
||||||
# write "image/TYPE" instead of "image/png" in the
|
# write "image/TYPE" instead of "image/png" in the
|
||||||
@@ -42,24 +43,18 @@
|
|||||||
#
|
#
|
||||||
# Requires /bin/sh and a "base64" or "uuencode -m" that encodes its input
|
# Requires /bin/sh and a "base64" or "uuencode -m" that encodes its input
|
||||||
# in base64 according to RFC-3548 and writes the result on standard output,
|
# in base64 according to RFC-3548 and writes the result on standard output,
|
||||||
# "uname", and a working "sed".
|
# and a working "sed".
|
||||||
#
|
#
|
||||||
# If you prefer a web-based converter or a java application, this isn't
|
# If you prefer a web-based converter or a java application, this isn't
|
||||||
# it. Use your search engine and look for "data uri" to find one.
|
# it. Use your search engine and look for "data uri" to find one.
|
||||||
#
|
#
|
||||||
# I guess we need a "configure" script to figure out which of base64(1)
|
# This script figures out which of base64(1) or uuencode(1) to use, since
|
||||||
# or uuencode(1) to use, since neither is always present (uuencode must
|
# neither is always present (uuencode must be installed as part of "sharutils"
|
||||||
# be installed as part of "sharutils" on Gnu/Linux platforms, which often
|
# on Gnu/Linux platforms, which often hasn't happened).
|
||||||
# hasn't happened). Here is a minimal "configure":
|
|
||||||
|
|
||||||
case X`uname` in
|
png2uri_encode(){
|
||||||
XLinux)
|
base64 2>/dev/null || uuencode -m "====" 2>/dev/null | grep -v "===="
|
||||||
PNG2URI_BASE64=use_base64
|
}
|
||||||
;;
|
|
||||||
*)
|
|
||||||
PNG2URI_BASE64=use_uuencode
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
PNG2URI_FMT="unknown"
|
PNG2URI_FMT="unknown"
|
||||||
PNG2URI_URI="true"
|
PNG2URI_URI="true"
|
||||||
@@ -110,26 +105,12 @@ case X$1 in
|
|||||||
case X$PNG2URI_URI in
|
case X$PNG2URI_URI in
|
||||||
Xfalse)
|
Xfalse)
|
||||||
echo "data:$PNG2URI_FMT;base64,"
|
echo "data:$PNG2URI_FMT;base64,"
|
||||||
case X$PNG2URI_BASE64 in
|
png2uri_encode
|
||||||
Xuse_base64)
|
|
||||||
base64
|
|
||||||
;;
|
|
||||||
Xuse_uuencode)
|
|
||||||
uuencode -m ==== | grep -v ====
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "<img alt=\"PNG\" title=\"PNG\" src=\"data:$PNG2URI_FMT;base64,"
|
echo "<img alt=\"PNG\" title=\"PNG\" src=\"data:$PNG2URI_FMT;base64,"
|
||||||
case X$PNG2URI_BASE64 in
|
png2uri_encode
|
||||||
Xuse_base64)
|
|
||||||
base64
|
|
||||||
;;
|
|
||||||
Xuse_uuencode)
|
|
||||||
uuencode -m ==== | grep -v ====
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
echo "\">"
|
echo "\">"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -138,12 +119,28 @@ case X$1 in
|
|||||||
|
|
||||||
*)
|
*)
|
||||||
# Convert the named file.
|
# Convert the named file.
|
||||||
|
|
||||||
|
# First make sure there weren't extra arguments
|
||||||
|
case $# in
|
||||||
|
1)
|
||||||
|
: # OK, continue
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
exec < "$1" > "$2"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "png2uri: too many arguments: $*" >&2
|
||||||
|
echo "usage: png2uri [options] [infile [outfile]" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
case X$PNG2URI_FMT in
|
case X$PNG2URI_FMT in
|
||||||
Xunknown)
|
Xunknown)
|
||||||
PNG2URI_FMT=image/png
|
PNG2URI_FMT=image/png
|
||||||
extension=`echo $1 | sed "s/.*\.//"`
|
png2uri_extension=`echo $1 | sed "s/.*\.//"`
|
||||||
|
|
||||||
case X$extension in
|
case X$png2uri_extension in
|
||||||
Xjpeg|XJPEG|Xjpg|XJPG)
|
Xjpeg|XJPEG|Xjpg|XJPG)
|
||||||
PNG2URI_FMT=image/jpeg
|
PNG2URI_FMT=image/jpeg
|
||||||
;;
|
;;
|
||||||
@@ -162,25 +159,11 @@ case X$1 in
|
|||||||
case X$PNG2URI_URI in
|
case X$PNG2URI_URI in
|
||||||
Xfalse)
|
Xfalse)
|
||||||
echo "data:$PNG2URI_FMT;base64,"
|
echo "data:$PNG2URI_FMT;base64,"
|
||||||
case X$PNG2URI_BASE64 in
|
png2uri_encode < "$1"
|
||||||
Xuse_base64)
|
|
||||||
base64 < $1
|
|
||||||
;;
|
|
||||||
Xuse_uuencode)
|
|
||||||
uuencode -m $1 ==== | grep -v ====
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "<img alt=\"$1\" title=\"$1\" src=\"data:$PNG2URI_FMT;base64,"
|
echo "<img alt=\"$1\" title=\"$1\" src=\"data:$PNG2URI_FMT;base64,"
|
||||||
case X$PNG2URI_BASE64 in
|
png2uri_encode < "$1"
|
||||||
Xuse_base64)
|
|
||||||
base64 < $1
|
|
||||||
;;
|
|
||||||
Xuse_uuencode)
|
|
||||||
uuencode -m $1 ==== | grep -v ====
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
echo "\">"
|
echo "\">"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
or "--format" option or, if that option was not supplied, by inspection of
|
or "--format" option or, if that option was not supplied, by inspection of
|
||||||
the filename extension.
|
the filename extension.
|
||||||
|
|
||||||
Usage: png2uri [-f format|--format format] [-u|--uri_only] [file]
|
Usage: png2uri [-f format|--format format] [-u|--uri_only] [infile [outfile]]
|
||||||
|
|
||||||
options: -f|--format TYPE:
|
options: -f|--format TYPE:
|
||||||
write "image/TYPE" instead of "image/png" in the
|
write "image/TYPE" instead of "image/png" in the
|
||||||
@@ -112,48 +112,25 @@
|
|||||||
of "sharutils", which often doesnn't happen. SunOS and FreeBSD don't
|
of "sharutils", which often doesnn't happen. SunOS and FreeBSD don't
|
||||||
supply "base64" so we use "uuencode" instead.
|
supply "base64" so we use "uuencode" instead.
|
||||||
|
|
||||||
|
Version 1.0.5, July 7, 2012:
|
||||||
|
|
||||||
|
Eliminated use of "uname" and use the return of "base64" and "uuencode"
|
||||||
|
to select the workable one (checking "base64" first); suggested by
|
||||||
|
John Bowler. Added a check for too many arguments, also a JB suggestion.
|
||||||
|
Accept output filename as an optional final argument.
|
||||||
|
|
||||||
TO DO
|
TO DO
|
||||||
|
|
||||||
1. Test on various other platforms. I assume we'll soon find one that has
|
1. Test on various other platforms. I assume we'll soon find one that has
|
||||||
neither "uuencode" nor "base64". The following have been tried
|
neither "uuencode" nor "base64". The following have been tried
|
||||||
|
|
||||||
Ubuntu 10.04 (uuencode output was folded to 60 characters)
|
Ubuntu 10.04 (using "base64")
|
||||||
Linux glenn.rp 2.6.32-41-generic #91-Ubuntu SMP Wed Jun 13 11:43:55
|
Ubuntu 12.04 (using "base64")
|
||||||
UTC 2012 x86_64 GNU/Linux
|
SunOS 5.10 (using "uuencode")
|
||||||
Linux nancy.rp 2.6.32-41-generic #91-Ubuntu SMP Wed Jun 13 11:43:55
|
SunOS 5.11 (using "uuencode")
|
||||||
UTC 2012 x86_64 GNU/Linux (uuencode not found. Fixed that with
|
FreeBSD 8.0 (using "uuencode")
|
||||||
"sudo aptitude install sharutils", then finally fixed by using
|
Redhat Gnu/Linux (using "base64")
|
||||||
base64() instead of uuencode())
|
Redhat Enterprise (using "base64")
|
||||||
|
|
||||||
Ubuntu 12.04 (uuencode not found but manpage for POSIX uuencode exists;
|
|
||||||
base64 works)
|
|
||||||
Linux scooby 3.0.0-22-generic #36-Ubuntu SMP Tue Jun 12 17:37:42 UTC 2012
|
|
||||||
x86_64 x86_64 x86_64 GNU/Linux
|
|
||||||
|
|
||||||
SunOS 5.10 (uuencode data is folded to 68 characters)
|
|
||||||
Does not work with "base64"! Reconfigured png2uri to use "uuencode".
|
|
||||||
on non-Linux platforms.
|
|
||||||
SunOS freddy 5.10 Generic_147441-13 i86pc i386 i86pc
|
|
||||||
SunOS blade 5.10 Generic_144488-12 sun4u sparc SUNW,Sun-Blade-2500
|
|
||||||
|
|
||||||
Sunos 5.11 (uuencode data is folded to 68 characters)
|
|
||||||
SunOS weerd 5.11 oi_151a4 i86pc i386 i86pc
|
|
||||||
|
|
||||||
FreeBSD 8.0 (uuencode data is folded to 76 characters)
|
|
||||||
"base64 not found"; use uuencode.
|
|
||||||
FreeBSD shaggy.simplesystems.org 8.0-RELEASE-p1 FreeBSD 8.0-RELEASE-p1
|
|
||||||
#1: Mon Dec 21 11:26:14 CST 2009
|
|
||||||
zsh@shaggy.simplesystems.org:/usr/src/sys/i386/compile/GENERIC
|
|
||||||
i386
|
|
||||||
|
|
||||||
Red Hat? (uuencode not found but manpage for POSIX uuencode
|
|
||||||
exists; worked when base64 was used instead of uuencode)
|
|
||||||
Linux studio.imagemagick.org 2.6.18-308.4.1.el5xen #1 SMP Tue Apr 17
|
|
||||||
17:49:15 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
|
|
||||||
Linux magick.imagemagick.org 3.4.4-3.fc17.x86_64 #1 SMP Tue Jun 26
|
|
||||||
20:54:56 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
|
|
||||||
Two other Redhat Enterprise platforms also worked with base64, but
|
|
||||||
uuencode was not installed.
|
|
||||||
|
|
||||||
2. Find out if the script works on Windows and Mac or can be modified to
|
2. Find out if the script works on Windows and Mac or can be modified to
|
||||||
do so.
|
do so.
|
||||||
|
|||||||
Reference in New Issue
Block a user