# Tk supports only GIF?

**URL:** <https://www.ruby-forum.com/t/tk-supports-only-gif/158363>\
**Category:** Ruby\
**Created:** [January 22, 2009, 2:00pm UTC](https://www.ruby-forum.com/t/tk-supports-only-gif/158363 "2009-01-22T14:00:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 22, 2009, 2:00pm UTC](https://www.ruby-forum.com/t/tk-supports-only-gif/158363/1 "2009-01-22T14:00:39Z")

</div>

I has this snippet to show images:

require ‘tk’

TkLabel.new do  
image TkPhotoImage.new(‘file’=\> ‘world.gif’)  
end.pack

Tk.mainloop

But if I point it to some PNG or JPEG file, I get a “couldn’t recognize  
data in image file” exception. If I add an explicit ‘format’ =\> ‘png’, I  
get a “image file format ‘png’ is not supported” exception.

I’m using Ubuntu.

Doesn’t Tk support JPGs and PNGs out of the box?

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 22, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/tk-supports-only-gif/158363/2 "2009-01-22T18:00:30Z")

</div>

From: Albert S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Tk supports only GIF?  
Date: Thu, 22 Jan 2009 21:58:54 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I’m using Ubuntu.
> 
> Doesn’t Tk support JPGs and PNGs out of the box?

If you talk about standard Tcl/Tk only, the answer is “YES”  
(see “man n photo”).  
To support JPEGs, PNGs, and so on, Tcl/Tk needs “Img” extension.

# Possibly, ubuntu package name is “libtk-img”.

When your Tcl/Tk has “Img” extension, Ruby/Tk also supports it.  
Please call “require ‘tkextlib/tkimg’”, and you can use JPEGs and  
PNGs on your Ruby/Tk.

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 25, 2009, 12:09am UTC](https://www.ruby-forum.com/t/tk-supports-only-gif/158363/3 "2009-01-25T00:09:26Z")

</div>

Hidetoshi NAGAI wrote:

> Possibly, ubuntu package name is “libtk-img”.  
> […]  
> Please call “require ‘tkextlib/tkimg’”

Thanks! these two tips solved my problem.

> > Doesn’t Tk support JPGs and PNGs out of the box?
> 
> If you talk about standard Tcl/Tk only, the answer is “YES”

BTW, I’m not sure I understand what you wrote here. (What does "standard  
Tcl/Tk mean?)

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 26, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/tk-supports-only-gif/158363/4 "2009-01-26T18:49:19Z")

</div>

Hidetoshi NAGAI wrote:

> From: Albert S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> > BTW […] what does “standard Tcl/Tk” mean?
> 
> I said it as “Tcl/Tk with no extension”.
> 
> As you know, Ruby/Tk uses Tcl/Tk libraries.  
> It means that functions supported by your Ruby/Tk depend on your  
> Tcl/Tk on your environment.  
> […]  
> Ruby/Tk can use almost all of Tcl/Tk extensions.  
> For some of them, Ruby/Tk has wrapper libraries (“tkextlib/\*”).  
> For others, although there are no wrapper libraries, Ruby/Tk can call  
> functions of those extensions directly (by “Tk.tk\_call” method) […]

Thank you for the thorough explanation!

(It’s a pity we don’t have a wiki to collect TK-related info. I did  
search for one.)

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 25, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/tk-supports-only-gif/158363/5 "2009-01-25T21:03:34Z")

</div>

From: Albert S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: Tk supports only GIF?  
Date: Sun, 25 Jan 2009 08:07:29 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > If you talk about standard Tcl/Tk only, the answer is “YES”  
> > BTW, I’m not sure I understand what you wrote here. (What does "standard  
> > Tcl/Tk mean?)

I’m sorry about my poor English.  
I said it as “Tcl/Tk with no extension”.

As you know, Ruby/Tk uses Tcl/Tk libraries.  
It means that functions supported by your Ruby/Tk depend on your  
Tcl/Tk on your environment.

When you have no Tcl/Tk extensions on your environment,  
Ruby/Tk can use Tcl/Tk’s standard (built-in) widgets and functions only.  
Tcl/Tk’s “photo” manual describes “At present, only GIF and PPM/PGM  
formats are supported”.  
Tcl/Tk’s “Img” extension library (loadable module) adds support for  
some other image formats to Tcl/Tk.  
And then, Ruby/Tk can treat image formats supported by “Img” extension.

Ruby/Tk can use almost all of Tcl/Tk extensions.  
For some of them, Ruby/Tk has wrapper libraries (“tkextlib/\*”).  
For others, although there are no wrapper libraries, Ruby/Tk can call  
functions of those extensions directly (by “Tk.tk\_call” method),  
I think that it is not so difficult to write a wrapper library for  
such a extension.

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 27, 2009, 6:25pm UTC](https://www.ruby-forum.com/t/tk-supports-only-gif/158363/6 "2009-01-27T18:25:32Z")

</div>

Albert S. wrote:

> > For some of them, Ruby/Tk has wrapper libraries (“tkextlib/\*”).  
> > For others, although there are no wrapper libraries, Ruby/Tk can call  
> > functions of those extensions directly (by “Tk.tk\_call” method) […]
> 
> Thank you for the thorough explanation!
> 
> (It’s a pity we don’t have a wiki to collect TK-related info. I did  
> search for one.)

The Tcl community itself has an excellent wiki:

> **[Welcome to the Tcler's Wiki!](https://wiki.tcl-lang.org/)**
>
> Tclers wiki

While there isn’t much Ruby-specific content there, there is a huge  
amount of information about Tk.
