Apply transparent background in GIMP












16















How can I remove the background and replace with transparency (as represented by checkered background in PS)? And are there any limitations in the file type I can then export the image to?










share|improve this question





























    16















    How can I remove the background and replace with transparency (as represented by checkered background in PS)? And are there any limitations in the file type I can then export the image to?










    share|improve this question



























      16












      16








      16


      3






      How can I remove the background and replace with transparency (as represented by checkered background in PS)? And are there any limitations in the file type I can then export the image to?










      share|improve this question
















      How can I remove the background and replace with transparency (as represented by checkered background in PS)? And are there any limitations in the file type I can then export the image to?







      gimp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 29 '17 at 19:49









      Zanna

      51k13138242




      51k13138242










      asked Jun 24 '11 at 15:06









      OxwiviOxwivi

      4,57742118184




      4,57742118184






















          6 Answers
          6






          active

          oldest

          votes


















          24















          1. Select Layer → Transparency → Add Alpha Channel


          2. Select the background using the Fuzzy Selection Tool (Magic Wand)



            and press the Del key.




          GIF will allow you single-color transparency, while PNG has full alpha channel support.






          share|improve this answer


























          • I found this while trying to get the "Color to Aplha" option enabled, unsuccessfully. It works well.

            – Ferdinand Prantl
            Oct 20 '13 at 13:59











          • It's not clear to me how this apply to GIFs (hundreds of layers).

            – Pablo Bianchi
            Mar 28 '18 at 4:58



















          2















          1. Open the image and choose Select > By Color from the menu.

          2. Click on the color you'd like to remove.

          3. Select Colors > Color to Alpha from the menu and click OK.


          This will result in the transparent, checkered background that you're looking for. If the background is made up of multiple colors, just repeat these three steps as necessary.






          share|improve this answer
























          • The Color to Alpha option doesn't activate.

            – Oxwivi
            Jun 24 '11 at 15:56











          • @Oxwivi, are you on Mac? I have to manually go to the window switcher (⌃↑ / 4-finger swipe up) and click on the filter window before I can interact with it at all. (This appears to be fixed in the GIMP 2.9.7 master branch.)

            – SilverWolf
            Dec 5 '17 at 18:55



















          1














          I've found the following to be easiest for me and I really like the effect.



          # Select Foreground
          Main Menu > Tools > Selection Tools > Foreground Select



          # Select Background
          Main Menu > Select > Invert



          # Make Transparent
          Main Menu > Colors > Color To Alpha



          Done






          share|improve this answer

































            1















            1. Select: Layer → Transparency → Add Alpha Channel


            2. Select: Background with Fuzzy Selection Tool (Magic Wand)


            3. Select: Layer → Transparency → Threshold Alpha...


            4. Set Threshold to 255 for complete transparency.







            share|improve this answer































              0














              Imagemagick



              Maybe a better solution from here but using ImageMagick -transparent is



              convert file.gif -transparent white -fuzz 10% file-2.gif`.


              You could use "#ededee" to specify the color in hexadecimal.



              Gimp



              Probably more complicated but there is an option to work with multiple layers/frames at once with this solution.






              share|improve this answer































                0














                Beware of simplistic solutions



                On CGI (logos, text), the smooth edges are produced with anti-aliasing pixels. These pixels have a color which is a mix of the background color and the subject color. When you use the color selector or the fuzzy selector, these pixels are either selected fully (if they are close enough) or not at all, depending on threshold. If you then bluntly Delete, you either get a halo with the color of the removed background (Threshold 15) or a jagged edge (Threshold 100) or both:



                ThresholdsThresholds-zoomed



                A good solution



                The good solution is to replace the background color by transparency, in proportion of its contribution to the color mix. In Gimp there are two ways to achieve this:




                • Colors>Color to alpha


                • Color erase mode, as a paint tool mode, or since Gimp 2.10 as a layer blend mode.


                They both replace the pixel by the most transparent pixel, which, put over the removed color, re-produces the initial color. If you remove red from purple, you get a semi transparent blue, because semi-transparent blue over red produces purple. If you remove white from gray, you get a very transparent black pixel and not a not-so-transparent dark gray pixel, because among several solution Gimp picks the most transparent one.



                For instance, using Color-to-alpha to remove the red gives this:



                Color-to-alpha resultsColor-to-alpha results zoomed



                You will notice that in the 2.8 results, there are darker pixels that are due to Gimp 2.8 working on gamma-corrected values (the result is still vastly better than the jagged edges you get with simpler methods). Gimp 2.10 works in "linear light" and has no such problems.



                Refinements



                In the general case, the subject may have parts that are close to the color of the background. So if you apply the technique above these parts become transparent (or partially transparent). Avoiding this is simple:




                • Use the wand to select the background. The usual threshold (15) is fine.


                • Select>Grow the selection so that it covers the anti-aliasing pixels. On a clean image (PNG, with no JPG history) you don't need to grow by more than one pixel. If the image is dirty (JPEG artifacts), growing the selection by two or three pixels can be necessary.

                • Apply color-to-alpha. The pixels inside the subject, bieng excluded from the selection, won't be altered. Color to alpha will be applied to the background and the edge pixels, where it matters.


                Output file types




                • JPEG doesn't support transparency

                • GIF supports binary transparency (all opaque or all transparent) so your semi-transparent edge pixels are going to be altered. You can use `Layer>Transparency>Semi-flatten to fill the transparency of these edge pixels with a new color (the color of the background on which the GIF will be used).

                • PNG has full support for partial transparency and is currently the preferred format.

                • WEBP is a new Google-sponsored format that can be lossy or lossless, and supports partial transparency. Gimp 2.10 supports it, but you have to ensure that it is supported where you want to use it (it won't be supported in older browsers, for instance).






                share|improve this answer

























                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "89"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f50375%2fapply-transparent-background-in-gimp%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  6 Answers
                  6






                  active

                  oldest

                  votes








                  6 Answers
                  6






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  24















                  1. Select Layer → Transparency → Add Alpha Channel


                  2. Select the background using the Fuzzy Selection Tool (Magic Wand)



                    and press the Del key.




                  GIF will allow you single-color transparency, while PNG has full alpha channel support.






                  share|improve this answer


























                  • I found this while trying to get the "Color to Aplha" option enabled, unsuccessfully. It works well.

                    – Ferdinand Prantl
                    Oct 20 '13 at 13:59











                  • It's not clear to me how this apply to GIFs (hundreds of layers).

                    – Pablo Bianchi
                    Mar 28 '18 at 4:58
















                  24















                  1. Select Layer → Transparency → Add Alpha Channel


                  2. Select the background using the Fuzzy Selection Tool (Magic Wand)



                    and press the Del key.




                  GIF will allow you single-color transparency, while PNG has full alpha channel support.






                  share|improve this answer


























                  • I found this while trying to get the "Color to Aplha" option enabled, unsuccessfully. It works well.

                    – Ferdinand Prantl
                    Oct 20 '13 at 13:59











                  • It's not clear to me how this apply to GIFs (hundreds of layers).

                    – Pablo Bianchi
                    Mar 28 '18 at 4:58














                  24












                  24








                  24








                  1. Select Layer → Transparency → Add Alpha Channel


                  2. Select the background using the Fuzzy Selection Tool (Magic Wand)



                    and press the Del key.




                  GIF will allow you single-color transparency, while PNG has full alpha channel support.






                  share|improve this answer
















                  1. Select Layer → Transparency → Add Alpha Channel


                  2. Select the background using the Fuzzy Selection Tool (Magic Wand)



                    and press the Del key.




                  GIF will allow you single-color transparency, while PNG has full alpha channel support.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 10 at 3:22









                  Glorfindel

                  2773513




                  2773513










                  answered Jun 24 '11 at 16:01









                  htorquehtorque

                  47.6k32175213




                  47.6k32175213













                  • I found this while trying to get the "Color to Aplha" option enabled, unsuccessfully. It works well.

                    – Ferdinand Prantl
                    Oct 20 '13 at 13:59











                  • It's not clear to me how this apply to GIFs (hundreds of layers).

                    – Pablo Bianchi
                    Mar 28 '18 at 4:58



















                  • I found this while trying to get the "Color to Aplha" option enabled, unsuccessfully. It works well.

                    – Ferdinand Prantl
                    Oct 20 '13 at 13:59











                  • It's not clear to me how this apply to GIFs (hundreds of layers).

                    – Pablo Bianchi
                    Mar 28 '18 at 4:58

















                  I found this while trying to get the "Color to Aplha" option enabled, unsuccessfully. It works well.

                  – Ferdinand Prantl
                  Oct 20 '13 at 13:59





                  I found this while trying to get the "Color to Aplha" option enabled, unsuccessfully. It works well.

                  – Ferdinand Prantl
                  Oct 20 '13 at 13:59













                  It's not clear to me how this apply to GIFs (hundreds of layers).

                  – Pablo Bianchi
                  Mar 28 '18 at 4:58





                  It's not clear to me how this apply to GIFs (hundreds of layers).

                  – Pablo Bianchi
                  Mar 28 '18 at 4:58













                  2















                  1. Open the image and choose Select > By Color from the menu.

                  2. Click on the color you'd like to remove.

                  3. Select Colors > Color to Alpha from the menu and click OK.


                  This will result in the transparent, checkered background that you're looking for. If the background is made up of multiple colors, just repeat these three steps as necessary.






                  share|improve this answer
























                  • The Color to Alpha option doesn't activate.

                    – Oxwivi
                    Jun 24 '11 at 15:56











                  • @Oxwivi, are you on Mac? I have to manually go to the window switcher (⌃↑ / 4-finger swipe up) and click on the filter window before I can interact with it at all. (This appears to be fixed in the GIMP 2.9.7 master branch.)

                    – SilverWolf
                    Dec 5 '17 at 18:55
















                  2















                  1. Open the image and choose Select > By Color from the menu.

                  2. Click on the color you'd like to remove.

                  3. Select Colors > Color to Alpha from the menu and click OK.


                  This will result in the transparent, checkered background that you're looking for. If the background is made up of multiple colors, just repeat these three steps as necessary.






                  share|improve this answer
























                  • The Color to Alpha option doesn't activate.

                    – Oxwivi
                    Jun 24 '11 at 15:56











                  • @Oxwivi, are you on Mac? I have to manually go to the window switcher (⌃↑ / 4-finger swipe up) and click on the filter window before I can interact with it at all. (This appears to be fixed in the GIMP 2.9.7 master branch.)

                    – SilverWolf
                    Dec 5 '17 at 18:55














                  2












                  2








                  2








                  1. Open the image and choose Select > By Color from the menu.

                  2. Click on the color you'd like to remove.

                  3. Select Colors > Color to Alpha from the menu and click OK.


                  This will result in the transparent, checkered background that you're looking for. If the background is made up of multiple colors, just repeat these three steps as necessary.






                  share|improve this answer














                  1. Open the image and choose Select > By Color from the menu.

                  2. Click on the color you'd like to remove.

                  3. Select Colors > Color to Alpha from the menu and click OK.


                  This will result in the transparent, checkered background that you're looking for. If the background is made up of multiple colors, just repeat these three steps as necessary.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 24 '11 at 15:29









                  kylankylan

                  563




                  563













                  • The Color to Alpha option doesn't activate.

                    – Oxwivi
                    Jun 24 '11 at 15:56











                  • @Oxwivi, are you on Mac? I have to manually go to the window switcher (⌃↑ / 4-finger swipe up) and click on the filter window before I can interact with it at all. (This appears to be fixed in the GIMP 2.9.7 master branch.)

                    – SilverWolf
                    Dec 5 '17 at 18:55



















                  • The Color to Alpha option doesn't activate.

                    – Oxwivi
                    Jun 24 '11 at 15:56











                  • @Oxwivi, are you on Mac? I have to manually go to the window switcher (⌃↑ / 4-finger swipe up) and click on the filter window before I can interact with it at all. (This appears to be fixed in the GIMP 2.9.7 master branch.)

                    – SilverWolf
                    Dec 5 '17 at 18:55

















                  The Color to Alpha option doesn't activate.

                  – Oxwivi
                  Jun 24 '11 at 15:56





                  The Color to Alpha option doesn't activate.

                  – Oxwivi
                  Jun 24 '11 at 15:56













                  @Oxwivi, are you on Mac? I have to manually go to the window switcher (⌃↑ / 4-finger swipe up) and click on the filter window before I can interact with it at all. (This appears to be fixed in the GIMP 2.9.7 master branch.)

                  – SilverWolf
                  Dec 5 '17 at 18:55





                  @Oxwivi, are you on Mac? I have to manually go to the window switcher (⌃↑ / 4-finger swipe up) and click on the filter window before I can interact with it at all. (This appears to be fixed in the GIMP 2.9.7 master branch.)

                  – SilverWolf
                  Dec 5 '17 at 18:55











                  1














                  I've found the following to be easiest for me and I really like the effect.



                  # Select Foreground
                  Main Menu > Tools > Selection Tools > Foreground Select



                  # Select Background
                  Main Menu > Select > Invert



                  # Make Transparent
                  Main Menu > Colors > Color To Alpha



                  Done






                  share|improve this answer






























                    1














                    I've found the following to be easiest for me and I really like the effect.



                    # Select Foreground
                    Main Menu > Tools > Selection Tools > Foreground Select



                    # Select Background
                    Main Menu > Select > Invert



                    # Make Transparent
                    Main Menu > Colors > Color To Alpha



                    Done






                    share|improve this answer




























                      1












                      1








                      1







                      I've found the following to be easiest for me and I really like the effect.



                      # Select Foreground
                      Main Menu > Tools > Selection Tools > Foreground Select



                      # Select Background
                      Main Menu > Select > Invert



                      # Make Transparent
                      Main Menu > Colors > Color To Alpha



                      Done






                      share|improve this answer















                      I've found the following to be easiest for me and I really like the effect.



                      # Select Foreground
                      Main Menu > Tools > Selection Tools > Foreground Select



                      # Select Background
                      Main Menu > Select > Invert



                      # Make Transparent
                      Main Menu > Colors > Color To Alpha



                      Done







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jun 29 '17 at 19:48









                      Zanna

                      51k13138242




                      51k13138242










                      answered Jun 28 '17 at 23:25









                      Prisoner 13Prisoner 13

                      113




                      113























                          1















                          1. Select: Layer → Transparency → Add Alpha Channel


                          2. Select: Background with Fuzzy Selection Tool (Magic Wand)


                          3. Select: Layer → Transparency → Threshold Alpha...


                          4. Set Threshold to 255 for complete transparency.







                          share|improve this answer




























                            1















                            1. Select: Layer → Transparency → Add Alpha Channel


                            2. Select: Background with Fuzzy Selection Tool (Magic Wand)


                            3. Select: Layer → Transparency → Threshold Alpha...


                            4. Set Threshold to 255 for complete transparency.







                            share|improve this answer


























                              1












                              1








                              1








                              1. Select: Layer → Transparency → Add Alpha Channel


                              2. Select: Background with Fuzzy Selection Tool (Magic Wand)


                              3. Select: Layer → Transparency → Threshold Alpha...


                              4. Set Threshold to 255 for complete transparency.







                              share|improve this answer














                              1. Select: Layer → Transparency → Add Alpha Channel


                              2. Select: Background with Fuzzy Selection Tool (Magic Wand)


                              3. Select: Layer → Transparency → Threshold Alpha...


                              4. Set Threshold to 255 for complete transparency.








                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Feb 14 '18 at 4:50









                              Bob in DCBob in DC

                              111




                              111























                                  0














                                  Imagemagick



                                  Maybe a better solution from here but using ImageMagick -transparent is



                                  convert file.gif -transparent white -fuzz 10% file-2.gif`.


                                  You could use "#ededee" to specify the color in hexadecimal.



                                  Gimp



                                  Probably more complicated but there is an option to work with multiple layers/frames at once with this solution.






                                  share|improve this answer




























                                    0














                                    Imagemagick



                                    Maybe a better solution from here but using ImageMagick -transparent is



                                    convert file.gif -transparent white -fuzz 10% file-2.gif`.


                                    You could use "#ededee" to specify the color in hexadecimal.



                                    Gimp



                                    Probably more complicated but there is an option to work with multiple layers/frames at once with this solution.






                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      Imagemagick



                                      Maybe a better solution from here but using ImageMagick -transparent is



                                      convert file.gif -transparent white -fuzz 10% file-2.gif`.


                                      You could use "#ededee" to specify the color in hexadecimal.



                                      Gimp



                                      Probably more complicated but there is an option to work with multiple layers/frames at once with this solution.






                                      share|improve this answer













                                      Imagemagick



                                      Maybe a better solution from here but using ImageMagick -transparent is



                                      convert file.gif -transparent white -fuzz 10% file-2.gif`.


                                      You could use "#ededee" to specify the color in hexadecimal.



                                      Gimp



                                      Probably more complicated but there is an option to work with multiple layers/frames at once with this solution.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 28 '18 at 6:00









                                      Pablo BianchiPablo Bianchi

                                      2,92521535




                                      2,92521535























                                          0














                                          Beware of simplistic solutions



                                          On CGI (logos, text), the smooth edges are produced with anti-aliasing pixels. These pixels have a color which is a mix of the background color and the subject color. When you use the color selector or the fuzzy selector, these pixels are either selected fully (if they are close enough) or not at all, depending on threshold. If you then bluntly Delete, you either get a halo with the color of the removed background (Threshold 15) or a jagged edge (Threshold 100) or both:



                                          ThresholdsThresholds-zoomed



                                          A good solution



                                          The good solution is to replace the background color by transparency, in proportion of its contribution to the color mix. In Gimp there are two ways to achieve this:




                                          • Colors>Color to alpha


                                          • Color erase mode, as a paint tool mode, or since Gimp 2.10 as a layer blend mode.


                                          They both replace the pixel by the most transparent pixel, which, put over the removed color, re-produces the initial color. If you remove red from purple, you get a semi transparent blue, because semi-transparent blue over red produces purple. If you remove white from gray, you get a very transparent black pixel and not a not-so-transparent dark gray pixel, because among several solution Gimp picks the most transparent one.



                                          For instance, using Color-to-alpha to remove the red gives this:



                                          Color-to-alpha resultsColor-to-alpha results zoomed



                                          You will notice that in the 2.8 results, there are darker pixels that are due to Gimp 2.8 working on gamma-corrected values (the result is still vastly better than the jagged edges you get with simpler methods). Gimp 2.10 works in "linear light" and has no such problems.



                                          Refinements



                                          In the general case, the subject may have parts that are close to the color of the background. So if you apply the technique above these parts become transparent (or partially transparent). Avoiding this is simple:




                                          • Use the wand to select the background. The usual threshold (15) is fine.


                                          • Select>Grow the selection so that it covers the anti-aliasing pixels. On a clean image (PNG, with no JPG history) you don't need to grow by more than one pixel. If the image is dirty (JPEG artifacts), growing the selection by two or three pixels can be necessary.

                                          • Apply color-to-alpha. The pixels inside the subject, bieng excluded from the selection, won't be altered. Color to alpha will be applied to the background and the edge pixels, where it matters.


                                          Output file types




                                          • JPEG doesn't support transparency

                                          • GIF supports binary transparency (all opaque or all transparent) so your semi-transparent edge pixels are going to be altered. You can use `Layer>Transparency>Semi-flatten to fill the transparency of these edge pixels with a new color (the color of the background on which the GIF will be used).

                                          • PNG has full support for partial transparency and is currently the preferred format.

                                          • WEBP is a new Google-sponsored format that can be lossy or lossless, and supports partial transparency. Gimp 2.10 supports it, but you have to ensure that it is supported where you want to use it (it won't be supported in older browsers, for instance).






                                          share|improve this answer






























                                            0














                                            Beware of simplistic solutions



                                            On CGI (logos, text), the smooth edges are produced with anti-aliasing pixels. These pixels have a color which is a mix of the background color and the subject color. When you use the color selector or the fuzzy selector, these pixels are either selected fully (if they are close enough) or not at all, depending on threshold. If you then bluntly Delete, you either get a halo with the color of the removed background (Threshold 15) or a jagged edge (Threshold 100) or both:



                                            ThresholdsThresholds-zoomed



                                            A good solution



                                            The good solution is to replace the background color by transparency, in proportion of its contribution to the color mix. In Gimp there are two ways to achieve this:




                                            • Colors>Color to alpha


                                            • Color erase mode, as a paint tool mode, or since Gimp 2.10 as a layer blend mode.


                                            They both replace the pixel by the most transparent pixel, which, put over the removed color, re-produces the initial color. If you remove red from purple, you get a semi transparent blue, because semi-transparent blue over red produces purple. If you remove white from gray, you get a very transparent black pixel and not a not-so-transparent dark gray pixel, because among several solution Gimp picks the most transparent one.



                                            For instance, using Color-to-alpha to remove the red gives this:



                                            Color-to-alpha resultsColor-to-alpha results zoomed



                                            You will notice that in the 2.8 results, there are darker pixels that are due to Gimp 2.8 working on gamma-corrected values (the result is still vastly better than the jagged edges you get with simpler methods). Gimp 2.10 works in "linear light" and has no such problems.



                                            Refinements



                                            In the general case, the subject may have parts that are close to the color of the background. So if you apply the technique above these parts become transparent (or partially transparent). Avoiding this is simple:




                                            • Use the wand to select the background. The usual threshold (15) is fine.


                                            • Select>Grow the selection so that it covers the anti-aliasing pixels. On a clean image (PNG, with no JPG history) you don't need to grow by more than one pixel. If the image is dirty (JPEG artifacts), growing the selection by two or three pixels can be necessary.

                                            • Apply color-to-alpha. The pixels inside the subject, bieng excluded from the selection, won't be altered. Color to alpha will be applied to the background and the edge pixels, where it matters.


                                            Output file types




                                            • JPEG doesn't support transparency

                                            • GIF supports binary transparency (all opaque or all transparent) so your semi-transparent edge pixels are going to be altered. You can use `Layer>Transparency>Semi-flatten to fill the transparency of these edge pixels with a new color (the color of the background on which the GIF will be used).

                                            • PNG has full support for partial transparency and is currently the preferred format.

                                            • WEBP is a new Google-sponsored format that can be lossy or lossless, and supports partial transparency. Gimp 2.10 supports it, but you have to ensure that it is supported where you want to use it (it won't be supported in older browsers, for instance).






                                            share|improve this answer




























                                              0












                                              0








                                              0







                                              Beware of simplistic solutions



                                              On CGI (logos, text), the smooth edges are produced with anti-aliasing pixels. These pixels have a color which is a mix of the background color and the subject color. When you use the color selector or the fuzzy selector, these pixels are either selected fully (if they are close enough) or not at all, depending on threshold. If you then bluntly Delete, you either get a halo with the color of the removed background (Threshold 15) or a jagged edge (Threshold 100) or both:



                                              ThresholdsThresholds-zoomed



                                              A good solution



                                              The good solution is to replace the background color by transparency, in proportion of its contribution to the color mix. In Gimp there are two ways to achieve this:




                                              • Colors>Color to alpha


                                              • Color erase mode, as a paint tool mode, or since Gimp 2.10 as a layer blend mode.


                                              They both replace the pixel by the most transparent pixel, which, put over the removed color, re-produces the initial color. If you remove red from purple, you get a semi transparent blue, because semi-transparent blue over red produces purple. If you remove white from gray, you get a very transparent black pixel and not a not-so-transparent dark gray pixel, because among several solution Gimp picks the most transparent one.



                                              For instance, using Color-to-alpha to remove the red gives this:



                                              Color-to-alpha resultsColor-to-alpha results zoomed



                                              You will notice that in the 2.8 results, there are darker pixels that are due to Gimp 2.8 working on gamma-corrected values (the result is still vastly better than the jagged edges you get with simpler methods). Gimp 2.10 works in "linear light" and has no such problems.



                                              Refinements



                                              In the general case, the subject may have parts that are close to the color of the background. So if you apply the technique above these parts become transparent (or partially transparent). Avoiding this is simple:




                                              • Use the wand to select the background. The usual threshold (15) is fine.


                                              • Select>Grow the selection so that it covers the anti-aliasing pixels. On a clean image (PNG, with no JPG history) you don't need to grow by more than one pixel. If the image is dirty (JPEG artifacts), growing the selection by two or three pixels can be necessary.

                                              • Apply color-to-alpha. The pixels inside the subject, bieng excluded from the selection, won't be altered. Color to alpha will be applied to the background and the edge pixels, where it matters.


                                              Output file types




                                              • JPEG doesn't support transparency

                                              • GIF supports binary transparency (all opaque or all transparent) so your semi-transparent edge pixels are going to be altered. You can use `Layer>Transparency>Semi-flatten to fill the transparency of these edge pixels with a new color (the color of the background on which the GIF will be used).

                                              • PNG has full support for partial transparency and is currently the preferred format.

                                              • WEBP is a new Google-sponsored format that can be lossy or lossless, and supports partial transparency. Gimp 2.10 supports it, but you have to ensure that it is supported where you want to use it (it won't be supported in older browsers, for instance).






                                              share|improve this answer















                                              Beware of simplistic solutions



                                              On CGI (logos, text), the smooth edges are produced with anti-aliasing pixels. These pixels have a color which is a mix of the background color and the subject color. When you use the color selector or the fuzzy selector, these pixels are either selected fully (if they are close enough) or not at all, depending on threshold. If you then bluntly Delete, you either get a halo with the color of the removed background (Threshold 15) or a jagged edge (Threshold 100) or both:



                                              ThresholdsThresholds-zoomed



                                              A good solution



                                              The good solution is to replace the background color by transparency, in proportion of its contribution to the color mix. In Gimp there are two ways to achieve this:




                                              • Colors>Color to alpha


                                              • Color erase mode, as a paint tool mode, or since Gimp 2.10 as a layer blend mode.


                                              They both replace the pixel by the most transparent pixel, which, put over the removed color, re-produces the initial color. If you remove red from purple, you get a semi transparent blue, because semi-transparent blue over red produces purple. If you remove white from gray, you get a very transparent black pixel and not a not-so-transparent dark gray pixel, because among several solution Gimp picks the most transparent one.



                                              For instance, using Color-to-alpha to remove the red gives this:



                                              Color-to-alpha resultsColor-to-alpha results zoomed



                                              You will notice that in the 2.8 results, there are darker pixels that are due to Gimp 2.8 working on gamma-corrected values (the result is still vastly better than the jagged edges you get with simpler methods). Gimp 2.10 works in "linear light" and has no such problems.



                                              Refinements



                                              In the general case, the subject may have parts that are close to the color of the background. So if you apply the technique above these parts become transparent (or partially transparent). Avoiding this is simple:




                                              • Use the wand to select the background. The usual threshold (15) is fine.


                                              • Select>Grow the selection so that it covers the anti-aliasing pixels. On a clean image (PNG, with no JPG history) you don't need to grow by more than one pixel. If the image is dirty (JPEG artifacts), growing the selection by two or three pixels can be necessary.

                                              • Apply color-to-alpha. The pixels inside the subject, bieng excluded from the selection, won't be altered. Color to alpha will be applied to the background and the edge pixels, where it matters.


                                              Output file types




                                              • JPEG doesn't support transparency

                                              • GIF supports binary transparency (all opaque or all transparent) so your semi-transparent edge pixels are going to be altered. You can use `Layer>Transparency>Semi-flatten to fill the transparency of these edge pixels with a new color (the color of the background on which the GIF will be used).

                                              • PNG has full support for partial transparency and is currently the preferred format.

                                              • WEBP is a new Google-sponsored format that can be lossy or lossless, and supports partial transparency. Gimp 2.10 supports it, but you have to ensure that it is supported where you want to use it (it won't be supported in older browsers, for instance).







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited 2 days ago

























                                              answered Mar 10 at 14:03









                                              xenoidxenoid

                                              1,8331416




                                              1,8331416






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Ask Ubuntu!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f50375%2fapply-transparent-background-in-gimp%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  How did Captain America manage to do this?

                                                  迪纳利

                                                  南乌拉尔铁路局