Using TkPhotoImage

I am trying to convert a set of cards from a tcl/tk program that uses
data to create the image. I have been able to use a gif file to create
the image but would like to data as the tcl program does.

Here is the image in the tcl program
image create photo ::img::2d -format gif -data {
R0lGODlhRwBgAKEAAH//1AAAAP////8AACH5BAEAAAAALAAAAABHAGAAAAL/BIKpy+0PYzBH2I
uz3rz7L0wBSJamiZzquqbXAMPsTLtCjNP6acuWvwt6bBmg8JghvozIpvLGbCKVseNAmhwtr8Iq
1tLzRU84Lja8pJXHwXB5tvY6tdA3K87WPXd4+XGv1ufXRvfDJyhFNLjSd0ZnB4fn+LOmE/flcm
mZg6mluWk2SbkI93WhmGdaU3ijKuqqCgj7xzo7Z2sqi6tXu0vom9gLvDo8JVzccozMo7xcoutM
Ah39MU3dYX29ka2d1Z38rcIdHtJMjjEenv693t2u/X4dTz0fXe98v5yPvF/cP/wPWEBfA3cVxH
XQVsJZC2E1dPUwlrluocqd2+BnYcVAbnISklKh6SCkSHYKfrpTyaKURhyBDGTJEd1EMogseUMi
6OOMgDmDYYEJMqXKJkBpQjIplJEZlzOV6iQhhqmqp0ZlutpI8ubFURoigtrWFBkbr4HSgAlb7B
PZlqHW+txarQJcDhMMSLiLN+9dAwUAADs=}

Could someone help me convert this into ruby.

thank you

From: Ed Redman [email protected]
Subject: using TkPhotoImage
Date: Sat, 20 Oct 2007 23:30:06 +0900
Message-ID: [email protected]

I am trying to convert a set of cards from a tcl/tk program that uses
data to create the image. I have been able to use a gif file to create
the image but would like to data as the tcl program does.

Here is the image in the tcl program
image create photo ::img::2d -format gif -data {
(snip)
Could someone help me convert this into ruby.

Here you are.

require ‘tk’

puts ‘=============< pattern 1 >===========================’
Tk.ip_eval <<END_OF_TCL_SCRIPT
image create photo ::img::2d -format gif -data {
R0lGODlhRwBgAKEAAH//1AAAAP////8AACH5BAEAAAAALAAAAABHAGAAAAL/BIKpy+0PYzBH2I
uz3rz7L0wBSJamiZzquqbXAMPsTLtCjNP6acuWvwt6bBmg8JghvozIpvLGbCKVseNAmhwtr8Iq
1tLzRU84Lja8pJXHwXB5tvY6tdA3K87WPXd4+XGv1ufXRvfDJyhFNLjSd0ZnB4fn+LOmE/flcm
mZg6mluWk2SbkI93WhmGdaU3ijKuqqCgj7xzo7Z2sqi6tXu0vom9gLvDo8JVzccozMo7xcoutM
Ah39MU3dYX29ka2d1Z38rcIdHtJMjjEenv693t2u/X4dTz0fXe98v5yPvF/cP/wPWEBfA3cVxH
XQVsJZC2E1dPUwlrluocqd2+BnYcVAbnISklKh6SCkSHYKfrpTyaKURhyBDGTJEd1EMogseUMi
6OOMgDmDYYEJMqXKJkBpQjIplJEZlzOV6iQhhqmqp0ZlutpI8ubFURoigtrWFBkbr4HSgAlb7B
PZlqHW+txarQJcDhMMSLiLN+9dAwUAADs=}

label .l -image ::img::2d
pack .l
END_OF_TCL_SCRIPT
label_obj1 = TkComm.window(’.l’)
p [‘label_obj1’, label_obj1.image, label_obj1]

puts ‘=============< pattern 2 >===========================’
Tk.ip_eval <<END_OF_TCL_SCRIPT
image create photo ::img::2d -format gif -data {
R0lGODlhRwBgAKEAAH//1AAAAP////8AACH5BAEAAAAALAAAAABHAGAAAAL/BIKpy+0PYzBH2I
uz3rz7L0wBSJamiZzquqbXAMPsTLtCjNP6acuWvwt6bBmg8JghvozIpvLGbCKVseNAmhwtr8Iq
1tLzRU84Lja8pJXHwXB5tvY6tdA3K87WPXd4+XGv1ufXRvfDJyhFNLjSd0ZnB4fn+LOmE/flcm
mZg6mluWk2SbkI93WhmGdaU3ijKuqqCgj7xzo7Z2sqi6tXu0vom9gLvDo8JVzccozMo7xcoutM
Ah39MU3dYX29ka2d1Z38rcIdHtJMjjEenv693t2u/X4dTz0fXe98v5yPvF/cP/wPWEBfA3cVxH
XQVsJZC2E1dPUwlrluocqd2+BnYcVAbnISklKh6SCkSHYKfrpTyaKURhyBDGTJEd1EMogseUMi
6OOMgDmDYYEJMqXKJkBpQjIplJEZlzOV6iQhhqmqp0ZlutpI8ubFURoigtrWFBkbr4HSgAlb7B
PZlqHW+txarQJcDhMMSLiLN+9dAwUAADs=}
END_OF_TCL_SCRIPT
label_obj2 = TkLabel.new(:image=>’::img::2d’).pack
p [‘label_obj2’, label_obj2.image, label_obj2]

puts ‘=============< pattern 3 >===========================’
img = TkPhotoImage.new(:format=>‘gif’, :data=>’
R0lGODlhRwBgAKEAAH//1AAAAP////8AACH5BAEAAAAALAAAAABHAGAAAAL/BIKpy+0PYzBH2I
uz3rz7L0wBSJamiZzquqbXAMPsTLtCjNP6acuWvwt6bBmg8JghvozIpvLGbCKVseNAmhwtr8Iq
1tLzRU84Lja8pJXHwXB5tvY6tdA3K87WPXd4+XGv1ufXRvfDJyhFNLjSd0ZnB4fn+LOmE/flcm
mZg6mluWk2SbkI93WhmGdaU3ijKuqqCgj7xzo7Z2sqi6tXu0vom9gLvDo8JVzccozMo7xcoutM
Ah39MU3dYX29ka2d1Z38rcIdHtJMjjEenv693t2u/X4dTz0fXe98v5yPvF/cP/wPWEBfA3cVxH
XQVsJZC2E1dPUwlrluocqd2+BnYcVAbnISklKh6SCkSHYKfrpTyaKURhyBDGTJEd1EMogseUMi
6OOMgDmDYYEJMqXKJkBpQjIplJEZlzOV6iQhhqmqp0ZlutpI8ubFURoigtrWFBkbr4HSgAlb7B
PZlqHW+txarQJcDhMMSLiLN+9dAwUAADs=
')
label_obj3 = TkLabel.new(:image=>img).pack
p [‘label_obj3’, label_obj3.image, label_obj3]

puts ‘=============< image names >===========================’
p [‘TkImage.names’, TkImage.names]

puts '==========< create TkPhotoImage object for “::img::2d”

===========’
img2 = TkPhotoImage.new(:imagename=>’::img::2d’,
:without_creating=>true)
p [‘image for ::img::2d’, img2, img2.current_configinfo]

label_obj4 = TkLabel.new(:image=>img2).pack
p [‘label_obj4’, label_obj4.image, label_obj4]
p
[‘TkImage::Tk_IMGTBL[label_obj4.image]’,TkImage::Tk_IMGTBL[label_obj4.image]]

puts ‘=============< image names >===========================’
p [‘TkImage.names’, TkImage.names]

Tk.mainloop

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs