Reputation: 450
I have trouble displaying png/jpg image with ruby and tkextlib/tkimg
require 'tkextlib/tkimg'
root = TkRoot.new
root.title = "Window"
image = TkPhotoImage.new(:file => "/path/to/image.png")
label = TkLabel.new(root)
label.image = image
label.place('height' => image.height,
'width' => image.width,
'x' => 10, 'y' => 10)
Tk.mainloop
the error:
/Users/dragon/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/tk/package.rb:86:in `rescue in require': TkPackage dlopen(/System/Library/Tcl/8.5/Img1.4/libtkimgwindow1.4.dylib, 10): image not found (RuntimeError)
from /Users/dragon/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/tk/package.rb:83:in `require'
from /Users/dragon/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/tkextlib/tkimg.rb:16:in `<top (required)>'
from /Users/dragon/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/dragon/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from main.rb:1:in `<main>'
The code works with any *.gif type image but with jpg/png type of image it gives me the image not found error, but I'am 100% sure that the image exist at specified path.
also, tkextlib/tkimg should work with that types of images.
please help. Thank you.
ruby 2.2.4, os x: 10.11.6
also there should be no problem with priviledges as the image displays in similar code in python.
I tried to google a bit, but the code shown up should work.
also, is there any other way to display jpg image in ruby?
Upvotes: 1
Views: 442
Reputation: 54213
Your code works fine on my computer, for either jpg or png, with absolute or relative path. Do you have any "weird" character in your path name, like a whitespace? To be sure, you could try :
image_path = "/path/to/image.png"
puts File.exists?(image_path)
image = TkPhotoImage.new(:file => image_path)
ruby 2.0.0p481 on Mac Os X 10.9.5
Upvotes: 1