diff options
author | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2012-07-06 21:21:30 -0500 |
---|---|---|
committer | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2012-07-06 21:21:30 -0500 |
commit | 1d9126cf0e6122eb289b894b29b90f0bba11cf52 (patch) | |
tree | 73b91aa52990d95903d524694fab476bca8214ce | |
parent | 35fbb6e6de480daf33b74ff64eb7b277ddf9b954 (diff) | |
download | libpng-png2uri-1.0.4.tar.gz |
[png2uri] Version 1.0.4, added check whether to use base64 or uuencodepng2uri-1.0.4
depending on whether "uname" returns Linux or not.
-rwxr-xr-x | png2uri | 58 | ||||
-rw-r--r-- | png2uri-README.txt | 48 |
2 files changed, 84 insertions, 22 deletions
@@ -1,6 +1,6 @@ #!/bin/sh # -# png2uri version 1.0.3, July 5, 2012. +# png2uri version 1.0.4, July 6, 2012. # # NO COPYRIGHT RIGHTS ARE CLAIMED TO THIS SOFTWARE. # @@ -40,15 +40,29 @@ # omit the surrounding "img" tag and only write the # data URI. # -# Requires /bin/sh and a uuencode(1) that takes the "-m" option to mean -# to encode in base64 according to RFC-3548, and a working "sed". +# 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, +# "uname", 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 "data uri" to find one. # +# I guess we need a "configure" script to figure out which of base64(1) +# or uuencode(1) to use, since neither is always present (uuencode must +# be installed as part of "sharutils" on Gnu/Linux platforms, which often +# hasn't happened). Here is a minimal "configure": + +case X`uname` in + XLinux) + PNG2URI_BASE64=use_base64 + ;; + *) + PNG2URI_BASE64=use_uuencode + ;; +esac -PNG2URI_URI="true" PNG2URI_FMT="unknown" +PNG2URI_URI="true" while true do @@ -96,12 +110,26 @@ case X$1 in case X$PNG2URI_URI in Xfalse) echo "data:$PNG2URI_FMT;base64," - uuencode -m ==== | grep -v ==== + case X$PNG2URI_BASE64 in + Xuse_base64) + base64 + ;; + Xuse_uuencode) + uuencode -m ==== | grep -v ==== + ;; + esac ;; *) echo "<img alt=\"PNG\" title=\"PNG\" src=\"data:$PNG2URI_FMT;base64," - uuencode -m ==== | grep -v ==== + case X$PNG2URI_BASE64 in + Xuse_base64) + base64 + ;; + Xuse_uuencode) + uuencode -m ==== | grep -v ==== + ;; + esac echo "\">" ;; esac @@ -134,11 +162,25 @@ case X$1 in case X$PNG2URI_URI in Xfalse) echo "data:$PNG2URI_FMT;base64," - uuencode -m $1 ==== | grep -v ==== + case X$PNG2URI_BASE64 in + Xuse_base64) + base64 < $1 + ;; + Xuse_uuencode) + uuencode -m $1 ==== | grep -v ==== + ;; + esac ;; *) echo "<img alt=\"$1\" title=\"$1\" src=\"data:$PNG2URI_FMT;base64," - uuencode -m $1 ==== | grep -v ==== + case X$PNG2URI_BASE64 in + Xuse_base64) + base64 < $1 + ;; + Xuse_uuencode) + uuencode -m $1 ==== | grep -v ==== + ;; + esac echo "\">" ;; esac diff --git a/png2uri-README.txt b/png2uri-README.txt index 19e48239a..c91d7c0af 100644 --- a/png2uri-README.txt +++ b/png2uri-README.txt @@ -38,9 +38,14 @@ omit the surrounding "img" tag and only write the data URI. - Requires /bin/sh and a uuencode(1) that takes the "-m" option to mean - to encode in base64. A surprising number of machines that I've tried - (3 out of 9) don't have uuencode installed. + Requires /bin/sh and a base64(1) that encodes its input in base64 + according to RFC-3548 and writes the result on standard output, and + a working "sed". Versions 1.0.0 through 1.0.3 used uuencode(1) instead + of base64(), but a surprising number of machines that I've tried + (5 out of 11) don't have uuencode installed, while all 11 had base64(1) + which is a "core utility" rather than a "shar utility". Using base64() + has an additional advantage that the lines are always folded to the same + width, 76 characters wide, while uuencode sometimes writes shorter lines. REFERENCES: http://en.wikipedia.org/wiki/Data_URI_scheme @@ -99,47 +104,62 @@ of name conflict, and changed "uri_only" to PNG2URI_URI. Fixed some indentation. + Version 1.0.4, July 6, 2012: + + Use "base64" instead of "uuencode" when "uname" returns "Linux" to + generate the output, because "base64" seems to be more prevalently + available. On Gnu/Linux platforms, uuencode must be installed as part + of "sharutils", which often doesnn't happen. SunOS and FreeBSD don't + supply "base64" so we use "uuencode" instead. + TO DO - 1. Test on various platforms. The following have been tried + 1. Test on various other platforms. I assume we'll soon find one that has + neither "uuencode" nor "base64". The following have been tried - Ubuntu 10.04 (data is folded to 60 characters) + Ubuntu 10.04 (uuencode output was folded to 60 characters) Linux glenn.rp 2.6.32-41-generic #91-Ubuntu SMP Wed Jun 13 11:43:55 UTC 2012 x86_64 GNU/Linux Linux nancy.rp 2.6.32-41-generic #91-Ubuntu SMP Wed Jun 13 11:43:55 UTC 2012 x86_64 GNU/Linux (uuencode not found. Fixed that with - "sudo aptitude install sharutils", then data folded to 60 chars) + "sudo aptitude install sharutils", then finally fixed by using + base64() instead of uuencode()) - Ubuntu 12.04 (FAILED: uuencode not found but manpage for POSIX uuencode - exists) + 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 (data is folded to 68 characters) + 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 (data is folded to 68 characters) + Sunos 5.11 (uuencode data is folded to 68 characters) SunOS weerd 5.11 oi_151a4 i86pc i386 i86pc - FreeBSD 8.0 (data is folded to 76 characters) + 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? (FAILED: uuencode not found but manpage for POSIX uuencode - exists) + 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 do so. 3. Make it work as a drag-and-drop application. - 4. But keep it simple! + 4. But keep it simple! */ |