PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

[FIXED] How to convert gif to text, for inline access from a tk script?

 July 17, 2022     gif, tcl, tk     No comments   

Issue

I saw the following code in the famous tkdiff utility:

image create photo rediffImage -format gif -data {
R0lGODdhFAAUAPf/AAAAAIAAAACAAICAAAAAgIAAgACAgMDAwMDcwKbK8P/w1P/isf/Ujv/G
......
}

I have a gif image to include in my tk script. How can I convert it to data like this so that I don't have to call the separate gif file ?


Solution

It's base64 data. Tcl 8.6 includes a command for doing the conversion.

# Read the data in *as binary data*
set f [open yourfile.gif b]
set data [read $f]
close $f

# Do the encoding
set encodedData [binary encode base64 $data]

# Print the encoded version out; it's just plain ASCII text now
puts $encodedData

Note that you can add whatever whitespace you want to base64 data; it remains valid. This means that you can split up and indent the lines however you see fit.



Answered By - Donal Fellows
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing