Sunday, January 2, 2011

Changing the Opacity of gtk.Pixbuf


Photobomb has lacked the ability to set the opacity of images the way it could set the opacity of text and scribbles. This was because goocanvas.Image lacked this capability, and I could not figure out how to make a pixbuf transparent. I looked through all the pygtk docs, all the PIL docs, and all the cairo docs. I tried a bunch of things, and just couldn't make it happen.

I finally ended up with a solution that works (but is a tad slow on larger images). To start, you need a transparent PNG file loaded into a pixbuf. I do this by storing a transparent PNG image on disk. If I was slicker, I could probably create one out of thin air using the various pixbuf functionalities. You also need a pixbuf that you want to make transparent.

Anyway, given a transparent pixbuf, this function will set the transparency.

    def change_opacity(self, opacity):
"""
change_opacity - changes the opacity of pixbuf by combining
the pixbuf with a pixbuf derived from a transparent .png

arguments:
opacity - the degree of desired opacity (between 0 and 255)

returns: a pixbuf with the transperancy

"""

trans = self.transparent_img
width = self.pixbuf.get_width()
height = self.pixbuf.get_height()
trans = trans.scale_simple(width,height,gtk.gdk.INTERP_NEAREST)
self.pixbuf.composite(trans, 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, opacity)
return trans

I'm sharing it here in case someone else runs into this and can either use my solution, or offer a better one.

30 comments:

  1. Opacity Meter. Davinor TOM11 is a modern opacity and transmission meter optimized for thin materials like plastic films, sheets and papers rhopoint iq.

    ReplyDelete
  2. So nice and great blog post it's also helpful information all of us so thanks a lot for sharing this tips with us
    clipping path service

    ReplyDelete
  3. Thank You so much for this lovely post. Check out our photoshop drop shadow service

    ReplyDelete
  4. Are You Looking for windows 8/10 Problem Solution? Or Android Problem Solution? If Yes, Then Welcome To fixguider .It help to find their solution.

    ReplyDelete
  5. Are You looking for AhujaBD system in bangladesh or want to know ahuja pa system speaker price in bangladesh We Provide best ahuja conference system in bangladesh.

    ReplyDelete
  6. I am grateful to the owner of this blog which really shares this wonderful article. That is actually Fix Guider great and useful information. Thanks for sharing this post. I would like to read more ideas about this, keep going on.

    ReplyDelete
  7. Your strategy of changing the opacity is wonderful. Thanks for shaing with us!
    Fixwill

    ReplyDelete
  8. If you need quality SEO Services, Content Writing Services, Graphics Design Services, and Web Development Services, you can count on Creative Marketers BD. We are here to help your business to be a success! We can expand your business through reaching to the right audience.

    To expand your business locally or globally, Creative Marketers BD is the perfect choice for you. If you want to grow your business with the help of effective digital marketing works, Creative Marketers BD is available to assist you wholeheartedly.

    ReplyDelete
  9. If you are Looking for the best Massage Near Me Bangalore, then you have come to the right place. We have young models who offer b2b massaging. Female to male spa near me

    ReplyDelete
  10. Spa69 is top most Body To Body Massage service provider which is kept privacy of customer in a good manner to give best top most types massages by expert therapists.

    Massage parlour near me

    ReplyDelete
  11. A body always need the good massage. You should attempt one time our Female to male massage centre near me services!!

    ReplyDelete
  12. If you are frustrated in your life and looking for some changes, then it's high time. Make a plan and travel to Hyderabad spasweety and choose here Body to body massage spa near me service. It will remove your tension from life and make your life smooth

    ReplyDelete
  13. We assure you world class nuru massage service in Bangalore.Bella spa having special nuru therapist where you can get 100% satisfied service.

    Visit body to body massage spa near me

    ReplyDelete
  14. I am lishasingh the creator of this site. This blog is about massage providers in Bangalore that offer male and female body-to-body massage Bangalore. I've been writing extensively on various other subjects for over 10 years.I'm Lishasingh who founded Health Care Services in Bangalore. I've been offering body massage in bangalore massage therapy to clients for more than 20 years, and it's my love.

    ReplyDelete
  15. Now get you world class spa therapies in marathahalli.We give you private massage services like female to male, thai massage in best prices.Assured 100% satisfied service in our spa.

    Visit Female to male massage spa in marathahalli

    ReplyDelete
  16. Wonderful content thanks to this article post here

    Body massage in Chennai

    ReplyDelete
  17. INTRESTING!! It was good ,Thank you for Distributing with this us I never Ever forgot this Blog.
    Spa body massage in Indiranagar

    ReplyDelete
  18. this Excellent content! thanks for keep sharing more.
    Photoshop Drop Shadow Services

    ReplyDelete
  19. magine that your patient has body massage in pune a hamstring injury right in the middle of the posterior thigh. Here’s what we’re going to do.

    ReplyDelete
  20. This excellent style of massage therapy offers a great sensation of emotional and mental well-being in addition to encouraging physical relaxation. Visit female to male massage in hsr layout

    ReplyDelete
  21. Intuitive Connection: Discussing the b2b massage in hyderabad importance of establishing a genuine and respectful connection between the practitioner and the recipient.

    ReplyDelete
  22. Massage therapy can be used to female to male massage home service near me ease the pain associated with delayed onset of muscle soreness (DOMS) which is a soreness typically felt 24 to 48 hours following physical activity.

    ReplyDelete
  23. Osteoarthritis. In the first clinical trial looking hot massage in hyderabad at the effectiveness of Swedish massage for knee osteoarthritis

    ReplyDelete
  24. I have been searching in the online for long time for this type of wonderful post. In case, if you to know more on female to male body massage in chennai never hesitate to reach out at goodwill spa. You will feel stress free and completely relaxed with our body massage services.

    ReplyDelete
  25. Since there are many factors that impact low back pain and many types of low back pain, it is a good idea to visit at least

    ReplyDelete