Post Reply 

Changing a white background to transparent (.png)

Feb 20, 2011, 00:02
Post: #1
Changing a white background to transparent (.png)
I have a .png file of a WordPress logo that has a white background. I would like to take the white background and convert it to a transparent background. I am having a spot of trouble making it happen. Does anyone know of a good fool proof way to do it?

Thank you! Big Grin


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Feb 20, 2011, 00:24 (This post was last modified: Feb 20, 2011 00:25 by ofnuts.)
Post: #2
RE: Changing a white background to transparent (.png)
The canonical way is to use Color/Color to alpha and give the background color, but that doesn't work too well with white because it makes a lot of things semi-transparent. To avoid this, you have to protect most of the logo with a selection that excludes it. So:

- use select by color tool, with treshold of 0, no feathering and no antialiasing. Click on the background. This will select only pure white pixels in the background
- grow the selection by 2 pixels. The selection now includes the background, and the border pixels (anti-aliasing)
- use Color/Color to alpha with white (it will only applies to background and logo border)

Done.

[Image: 2Tvo0.png]

Visit this user's website Find all posts by this user
Quote this message in a reply
Feb 20, 2011, 18:37
Post: #3
RE: Changing a white background to transparent (.png)
(Feb 20, 2011 00:24)ofnuts Wrote:  - use select by color tool, with treshold of 0, no feathering and no antialiasing. Click on the background. This will select only pure white pixels in the background
I did a screen capture on sepoto's image and tried this and the result wasn't good at all. I backed up and used a threshold of 15, anitaliasing and feathering and followed the rest of your directions and it worked fine.
Find all posts by this user
Quote this message in a reply
Feb 20, 2011, 19:54
Post: #4
RE: Changing a white background to transparent (.png)
(Feb 20, 2011 18:37)kaloua3 Wrote:  
(Feb 20, 2011 00:24)ofnuts Wrote:  - use select by color tool, with treshold of 0, no feathering and no antialiasing. Click on the background. This will select only pure white pixels in the background
I did a screen capture on sepoto's image and tried this and the result wasn't good at all. I backed up and used a threshold of 15, anitaliasing and feathering and followed the rest of your directions and it worked fine.
Yes, I can reproduce your problem if I do a screen grab of the attachment thumbnail in the original post instead of using the real image... but if you look at it closely, its background is not uniform white, unlike the original image... (btw, using a threshold of 15 was too much, a threshold of 2 would have been enough)

My method assumes one is using the original file (of course the grey smear at the bottom of the original image has been removed)... in fact to check the results I went as far as:

- extracting the foreground as described, and save as PNG
- reload the image
- add a white background
- load the original image as another layer
- put it in difference mode: if the anti-aliasing isn't taken properly in account, the border remains visible, here I couldn't see anything
- confirm by using the histogram dialog to count the pixels: from memory, there were no pixels above a value of 2

[Image: 2Tvo0.png]

Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 12, 2011, 15:00
Post: #5
RE: Changing a white background to transparent (.png)
Easiest way, Magic Wand, click white around edge of the Logo, then a bit of Manual Editing... to change the bits of white to transparent. Took me about 2 minutes to finish Big Grin

So, Add Alpha Chanel, Magic Wand, Set Threshhold to about 70 and then click the white you want to remove, ctlt+x, white is gone, if it kills more than you want, just hit ctl+v...

Willy
Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 12, 2011, 17:12
Post: #6
RE: Changing a white background to transparent (.png)
(Mar 12, 2011 15:00)Willy Wrote:  Easiest way, Magic Wand, click white around edge of the Logo, then a bit of Manual Editing... to change the bits of white to transparent. Took me about 2 minutes to finish Big Grin

So, Add Alpha Chanel, Magic Wand, Set Threshhold to about 70 and then click the white you want to remove, ctlt+x, white is gone, if it kills more than you want, just hit ctl+v...

Willy
Yuck Smile Won't work properly in most cases... this is bound to produce a border that will be visible on some backgrounds. Your technique doesn't produce the semi-transparent pixels that are necessary for a smooth edge. So either you keep some background pixels, or you go too deep (and get a jagged edge).

[Image: 2Tvo0.png]

Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 12, 2011, 17:16
Post: #7
RE: Changing a white background to transparent (.png)
Or you just be very careful and do it well Big Grin, what I do

Remove most of the background, then set your threshold down some, and go around and remove the bits of Whiter bits that are left over, and you get something that looks decent enough for me Big Grin
Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 12, 2011, 17:33
Post: #8
RE: Changing a white background to transparent (.png)
(Mar 12, 2011 17:16)Willy Wrote:  Or you just be very careful and do it well Big Grin, what I do

Remove most of the background, then set your threshold down some, and go around and remove the bits of Whiter bits that are left over, and you get something that looks decent enough for me Big Grin
You cannot do it well with your method, unless you are willing to fix all pixels by hand. My results, that take around 20 seconds to produce:
   

Show me yours Smile

[Image: 2Tvo0.png]

Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 12, 2011, 17:54
Post: #9
RE: Changing a white background to transparent (.png)
I kept the white in mine that was part of the Logo, the only reason I said it should be done this way...

Took a bit longer, but it kept the white


Attached File(s) Thumbnail(s)
   
Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 12, 2011, 20:32
Post: #10
RE: Changing a white background to transparent (.png)
Wondering:
- why you worked on the thumbnail and not the original file.
- why no transparent background
- why the smear around the border

Keeping the inner white is otherwise a snap:
   

[Image: 2Tvo0.png]

Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 12, 2011, 20:34
Post: #11
RE: Changing a white background to transparent (.png)
lols well I failed X D, I just used Thumbnail cause it was smaller and never though of bigger version, the black was so you could see that there wasn't as much white and the Blur was so that some of my mistakes would be covered up X D, I was kind of hurrying
Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 15, 2011, 19:19
Post: #12
RE: Changing a white background to transparent (.png)
I've got a fairly similar situation to the above, but I have a few elements from different files that I'm merging into my final image. I was able to get it to about the level of Willy's above (transparent outside the logo, interior white parts left opaque).

However, I'm trying to make the background *semi-transparent* and cannot seem to do that. Fully transparent is no problem, but making it 50% transparent does not work for me.

Because I have multiple elements, I did this with (three) layers, with each layer having part of the logo (all non-logo parts being fully transparent), and the bottom (empty) layer being set to some level of opacity (say 50%).

When I save it as .png I merge visible layers, etc. Everything looks fine within GIMP, but when I display the final graphic in Firefox (3.6) the background is completely transparent.

If anyone has any thoughts as to what I've missed I would greatly appreciate it!

By the by, I'm an almost complete beginner to GIMP.

Thanks,

- Dave
Find all posts by this user
Quote this message in a reply
Mar 15, 2011, 19:38
Post: #13
RE: Changing a white background to transparent (.png)
(Mar 15, 2011 19:19)landbrake Wrote:  If anyone has any thoughts as to what I've missed I would greatly appreciate it!

I think I figured it out... I guess I need a color for the bottom layer (or white in my case) in order for it to have something to actually MAKE semi-transparent... when I filled the bottom layer with white and made it 50% transparent it worked just as I had hoped.

Sorry for the VERY newbie question!

- Dave
Find all posts by this user
Quote this message in a reply
Mar 15, 2011, 20:17
Post: #14
RE: Changing a white background to transparent (.png)
There are no newbie questions... Sometimes simple questions will uncover some hidden complexity. You should never be ashamed to ask, especially when you consider yourself a noob. Later, when you have a reputation at stake, it's a bit different Smile

[Image: 2Tvo0.png]

Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 29, 2011, 22:01 (This post was last modified: Mar 29, 2011 22:04 by Virago.)
Post: #15
RE: Changing a white background to transparent (.png)
I ran across this thread and was playing with the instructions given just to get my own feel for how it works. I selected the white background, then grew the selection by 2 pixels... so far so good. But when I opened the "Color to Alpha" dialog, the preview window showed that it was ignoring the selection and changing all of the white area to transparent. I kept scratching my head and going back to figure out what I was doing wrong with the selection. Finally I just hit OK and found that it worked as it should and respected the selection boundary. It was just the preview window that doesn't show the correct preview. Is this just me or is this normal? I don't recall noticing this behavior before.
   

[Image: viragogimpforumssig.png]
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Transparent stuff? Liwo_Jima 6 100 Jul 20, 2014 00:27
Last Post: Esper
  background changes colour Weatherlawyer 15 176 Jul 19, 2014 00:42
Last Post: ofnuts
  Background removal woes mrmailbox 6 116 Jul 14, 2014 16:44
Last Post: ofnuts
  Remove transparent background Asmita 9 129 Jul 10, 2014 08:24
Last Post: paynekj
  How do I remove a background? Phantasy 25 303 Jul 8, 2014 22:11
Last Post: fluffybunny2

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS