Isn't that wat the ImageWriteBase64 function is for?

43 views
Skip to first unread message

stofke

unread,
Oct 5, 2010, 10:24:18 AM10/5/10
to CFML Conventional Wisdom
From the Adobe docs:

<!--- This example shows how convert a BMP file to a Base64 string. ---
>
<cfset ImageWriteBase64(myImage,"jeffBase64.txt","bmp","yes")>

Matthew Woodward

unread,
Oct 5, 2010, 10:54:53 AM10/5/10
to cfml-convent...@googlegroups.com
Since you started a new thread your message has no context, so it's hard to determine what the "that" in your subject line is referring to.
--
Matthew Woodward
ma...@mattwoodward.com
http://blog.mattwoodward.com
identi.ca / Twitter: @mpwoodward

Please do not send me proprietary file formats such as Word, PowerPoint, etc. as attachments.
http://www.gnu.org/philosophy/no-word-attachments.html

Todd Rafferty

unread,
Oct 5, 2010, 10:56:52 AM10/5/10
to cfml-convent...@googlegroups.com

stofke

unread,
Oct 5, 2010, 5:25:37 PM10/5/10
to CFML Conventional Wisdom
Sorry didn't want to start a new thread I was indeed replying to the
thread about

Function: DataUri() Options

I was wondering if ImageWriteBase64 doesn't actually do the same.


On Oct 5, 4:56 pm, Todd Rafferty <web...@gmail.com> wrote:
> Pretty sure he's talking about the most recent group thread:http://groups.google.com/group/cfml-conventional-wisdom/browse_thread...
>
> On Tue, Oct 5, 2010 at 10:54 AM, Matthew Woodward <m...@mattwoodward.com>wrote:
>
>
>
> > Since you started a new thread your message has no context, so it's hard to
> > determine what the "that" in your subject line is referring to.
> > --
> > Matthew Woodward
> > m...@mattwoodward.com

stofke

unread,
Oct 5, 2010, 5:28:26 PM10/5/10
to CFML Conventional Wisdom
Ok I just noticed that this function actually writes it to a file,
instead of embedding it into the page. But still wouldn't it make
sense to use this and make the output to file optional?

Matthew Woodward

unread,
Oct 5, 2010, 5:39:25 PM10/5/10
to cfml-convent...@googlegroups.com
On Tue, Oct 5, 2010 at 2:28 PM, stofke <kristof....@gmail.com> wrote:
Ok I just noticed that this function actually writes it to a file,
instead of embedding it into the page.  But still wouldn't it make
sense to use this and make the output to file optional?

Well, first of all ImageWriteBase64 is Adobe CF specific (unless Railo has it and I'm not aware), and second, I like the more generic DataUri() because that will conceivably support more options (some of which were discussed in the other thread) as opposed to ImageWriteBase64 which would be specific to image data, and specific to base 64.

--
Matthew Woodward
ma...@mattwoodward.com

stofke

unread,
Oct 5, 2010, 5:46:25 PM10/5/10
to CFML Conventional Wisdom
And would that also support writing it to a file? I'm all for a more
generic DataUri().

Railo does support ImageWriteBase64, I just did a test:

<cfset myImage=ImageNew("cfwheels-logo.png")>
<!--- Convert the image to Base64 format and write it to a file.--->
<cfset ImageWriteBase64(myImage,"jeffBase64.txt","png","yes")>

which seems to work fine.

On Oct 5, 11:39 pm, Matthew Woodward <m...@mattwoodward.com> wrote:
> On Tue, Oct 5, 2010 at 2:28 PM, stofke <kristof.polleu...@gmail.com> wrote:
> > Ok I just noticed that this function actually writes it to a file,
> > instead of embedding it into the page.  But still wouldn't it make
> > sense to use this and make the output to file optional?
>
> Well, first of all ImageWriteBase64 is Adobe CF specific (unless Railo has
> it and I'm not aware), and second, I like the more generic DataUri() because
> that will conceivably support more options (some of which were discussed in
> the other thread) as opposed to ImageWriteBase64 which would be specific to
> image data, and specific to base 64.
>
> --
> Matthew Woodward
> m...@mattwoodward.comhttp://blog.mattwoodward.com

Matthew Woodward

unread,
Oct 5, 2010, 5:51:08 PM10/5/10
to cfml-convent...@googlegroups.com
On Tue, Oct 5, 2010 at 2:46 PM, stofke <kristof....@gmail.com> wrote:
And would that also support writing it to a file?  I'm all for a more
generic DataUri().

I suppose it could, but it wouldn't be what this function is for. DataUri() as it's proposed would be for displaying Base64 data on a web page. If you want to write Base64 data to a file there's other ways to do that.

--
Matthew Woodward
ma...@mattwoodward.com

stofke

unread,
Oct 5, 2010, 7:48:24 PM10/5/10
to CFML Conventional Wisdom
In Railo and Adobe CF it's possible to do this with base64() directly
to the browser.

Works in Railo and Adobe CF
---------------------------
<cfset photoBinary = fileReadBinary(expandPath( "./cfwheels-
logo.png" )) />
<cfoutput>
<img src="data:image/*;base64,#toBase64( photoBinary )#"/>
</cfoutput>

In Adobe CF you can also read a ColdFusion image object in and use
that but this not working in Railo.

Works only in Adobe CF
---------------------------
<cfimage name="photo" action="read" source="./cfwheels-logo.png"/>
<cfoutput>
<img src="data:image/*;base64,#toBase64( photoBinary )#"/>
</cfoutput>



On Oct 5, 11:51 pm, Matthew Woodward <m...@mattwoodward.com> wrote:
> On Tue, Oct 5, 2010 at 2:46 PM, stofke <kristof.polleu...@gmail.com> wrote:
> > And would that also support writing it to a file?  I'm all for a more
> > generic DataUri().
>
> I suppose it could, but it wouldn't be what this function is for. DataUri()
> as it's proposed would be for displaying Base64 data on a web page. If you
> want to write Base64 data to a file there's other ways to do that.
>
> --
> Matthew Woodward
> m...@mattwoodward.comhttp://blog.mattwoodward.com

Todd Rafferty

unread,
Oct 5, 2010, 7:58:33 PM10/5/10
to cfml-convent...@googlegroups.com
You shouldn't be using action="read" and should be using "readbinary"?

Peter Boughton

unread,
Oct 5, 2010, 8:03:53 PM10/5/10
to cfml-convent...@googlegroups.com
You're missing the point - the toDataUri() function would be a more
generic function capable of doing all of those AND more, with less
code.

For example, no need to waste memory with a variable, just read the
file and output to page:
<img src="#toDataUri("./myimage.png")#" />

And it's not limited to just images either:
<script>window.open( '#toDataUri(HtmlCode,"utf-8","Base64")#' )</script>

And if someone decides to start doing data URIs with Base85 (or any
other method) all it requires is a different argument code with
toDataUri and it'll work.

Reply all
Reply to author
Forward
0 new messages