# Image with emblem?

**URL:** <https://www.ruby-forum.com/t/image-with-emblem/210740>\
**Category:** Ruby-Gnome 2\
**Created:** [August 16, 2011, 10:54am UTC](https://www.ruby-forum.com/t/image-with-emblem/210740 "2011-08-16T10:54:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [August 16, 2011, 10:54am UTC](https://www.ruby-forum.com/t/image-with-emblem/210740/1 "2011-08-16T10:54:08Z")

</div>

Hello,

Is there a widget or simple combination of widgets that would display  
an image with an emblem?

I see this used in many GTK applications but can’t find any widget for  
it.

I will need a few buttons that could be constructed of standard images  
this way.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [August 16, 2011, 10:01pm UTC](https://www.ruby-forum.com/t/image-with-emblem/210740/2 "2011-08-16T22:01:51Z")

</div>

You mean to overlay an image on another image?

This is possible with Pixbuf. The standard ruby-gnome distribution has  
an example for that if I recall correctly.

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [August 17, 2011, 12:10pm UTC](https://www.ruby-forum.com/t/image-with-emblem/210740/3 "2011-08-17T12:10:50Z")

</div>

On 16 August 2011 22:01, Marc H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> You mean to overlay an image on another image?
> 
> This is possible with Pixbuf. The standard ruby-gnome distribution has  
> an example for that if I recall correctly.

Yes, it’s totally possible to create a new image combining two images  
using gdk or otherwise.

It’s nice that it’s possible to do with ruby-gnome2, too.

What I was asking if there was a widget that would not require  
actually combining the image. Ideally one that glade can display.

There is GLib::EmblemedIcon but no obvious way to display the icon as an  
image.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [August 17, 2011, 1:59pm UTC](https://www.ruby-forum.com/t/image-with-emblem/210740/4 "2011-08-17T13:59:06Z")

</div>

On 16 August 2011 22:01, Marc H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> You mean to overlay an image on another image?
> 
> This is possible with Pixbuf. The standard ruby-gnome distribution has  
> an example for that if I recall correctly.

More precisely, it has an example of overlaying an image over  
checkerboard.

The composite! method (and its description) is broken.

While the description mentions a check\_size parameter it’s not  
included in the parameter list.

The check\_size parameter (or whatever is on its expected position) can  
be set to zero which leads to gtk looping.

There is no way to set the dest\_x and dest\_y shown in the operation  
diagram.

The operation diagram shows the apple image applied with transparency  
but actual method puts black background in place of the image’s  
transparent pixels.

The check1 and check2 colors are integers but the meaning of the  
integers is not detailed. I set them to zero which might be  
responsible for the black background but sane color meanings values  
would assign full transparency to 0.

The second method call in the composite example actually does overlay  
an image with transparency as can be seen when the second and third  
call are swapped and the image not replaced with empty one in between  
but why it is so is somewhat of a mystery as the method parameters  
aren’t really described anywhere nor does the method match any C or  
python Pixbuf method.

Of course, there’s always the source.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [August 17, 2011, 6:29pm UTC](https://www.ruby-forum.com/t/image-with-emblem/210740/5 "2011-08-17T18:29:54Z")

</div>

On 17 August 2011 13:58, Michal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> transparent pixels.
> 
> The check1 and check2 colors are integers but the meaning of the  
> integers is not detailed. I set them to zero which might be  
> responsible for the black background but sane color meanings values  
> would assign full transparency to 0.

The example achieves transparency be leaving out the checkerboard  
arguments altogether.

Using that I can construct a combined image like this:

class Gtk::Widget  
def stock\_icon\_with\_emblem icon, emblem  
icon = render\_icon(icon ,Gtk::IconSize::DIALOG, nil).dup  
emblem = render\_icon(emblem ,Gtk::IconSize::BUTTON, nil)  
icon.composite! emblem, icon.width - emblem.width, icon.height -  
emblem.height, emblem.width, emblem.height, icon.width - emblem.width,  
icon.width - emblem.width, 1, 1, Gdk::Pixbuf::INTERP\_NEAREST, 255  
Gtk::Image.new icon  
end  
end

@builder[‘button\_restore’].image =  
@builder[‘button\_restore’].stock\_icon\_with\_emblem  
@builder[‘image\_disk’].stock, @builder[‘image\_down’].stock

Thanks

Michal
