8

I want to give the middle full opacity but let the border effect that is already existing.

7 Answers 7

5

Each layer in GIMP can have the transparency for each pixel specified in two ways, that add to each other:

If you imported a PNG file with transparency, you background layer already has an alpha channel - you can keep that untouched - Just right click on the layerś thumb on the Layers Dialog ctrl + L and pick Add Layer Mask - that way a mask is created. It behaves as a grayscale image, where black means transparency and white means opacity - you can select if you are painting on the actual layer or on its maks by clicking on the respective thumbnails - Just select the mask and paint it gray (by dragging and dropping a shade of gray on the canvas, or using the bucket fill) - and you have extra, prortional transparency for the whole image, without touching the original transparency levels.

Kitten with layer mask active

4

One option might be to convert a color in your image to transparency:

enter image description here

Go to Layer -> Transparency -> Color to Alpha

This way you can choose exactly what you want to be transparent by making it a certain color and then converting that color to transparency.

4

If I understand the question, you are starting with a colored area that is partially transparent throughout, but at the outside edges it gradually becomes completely transparent (so the edges appear "feathered" or "anti-aliased"); and you want to make the colored area completely opaque, except for the outside edges, which you still want to gradually become completely transparent, in the same proportion to their original transparency (to retain a similar "feathered" or "anti-aliased" appearance at the edges)?

If so, one way is to duplicate the original layer on top of itself, so that each partially transparent pixel adds to itself proportionally.

  • Since the pixels around the outside edge were originally less opaque than the pixels in the middle, the outside pixels will add to themselves less than the more opaque pixels in the middle.

Create additional duplicates of the original layer until the middle area reaches the desired opacity.

  • But don't add too many duplicate layers, because even after the middle area reaches complete opacity, the outside pixels will continue adding to themselves with each new duplicate layer, until they eventually become completely opaque themselves (and you will lose the "feathered" or "anti-aliased" appearance at the edges).

Note: This method applies to the entire layer, so to apply it to a specific selection, you would need to first move the selection to its own new layer (for example, using Select > Float, then Layer > To New Layer).

Gimp Layers


Before duplicating layers

Approximately 50% transparency in the center of the circle:

Before


After adding 5 duplicate layers

Approximately 0% transparency in the center of the circle (but still with "feathered" or "anti-aliased" edges):

After

6
  • Using a layer mask is so much simpler than this....
    – xenoid
    Feb 19, 2019 at 0:11
  • Sorry @xenoid, I can't figure out how to increase opacity (decrease transparency) using a layer mask; for me, even with the layer mask completely white (full opacity), the original image retains its 50% transparency from its alpha channel. Can you provide instructions for how to do it? Feb 19, 2019 at 2:08
  • It depends how you initialize the mask. If you use Transfer the layer's alpha channel you have full control. If you use other options, this is in addition (multiplication, actually) to the existing alpha, so you cannot increase the opacity. So the quickest method is to transfer the alpha channel, and use Curves/Levels/Brightness-Contrast to alter the channel.
    – xenoid
    Feb 19, 2019 at 10:33
  • Thanks @xenoid; using Levels > "Auto" on the layer mask (transferred from alpha channel) gave me the desired effect - and I think it's more mathematically accurate too. I know layer masks were mentioned in other answers here, but your suggestion was the key for me, so I think it would make a good answer to the OP's question, if you're willing to post it? Feb 20, 2019 at 8:11
  • Posted as an answer...
    – xenoid
    Feb 20, 2019 at 10:09
2

Not sure what you mean with "border effect" but here is how to have a transparent senter with a feathered border:

  1. Layer > Transparency > Add Alpha Channel adds a transparent layer to the image if not yet present.

  2. Select area with border effect (here Feather).

  3. Press Del or select Edit > Clear to remove selected area leaving the transparent layer in the background.

    enter image description here

3
  • I mean the .png I oopen in Gimp already has a good anti-aliasing effect (it's an Android star icon that I try to colorize, never though it would be that complex). I try your solution, brb
    – Poutrathor
    Nov 29, 2013 at 11:55
  • As far as I understand, your idea is to remove the picture and to keep only the alpha channel layer? Can I add a layer over an image to increase opacity unifomly?
    – Poutrathor
    Nov 29, 2013 at 12:01
  • Its the other way round: I removed the selection from the image to leave a transparent hole. Anything you paint on that transparent area will become the opacity of the paint tool used. So yes, you can add a layer to that image.
    – Takkat
    Nov 29, 2013 at 12:09
2

tl;dr

(Inspired by previous answers from xenoid and Reece.)

Adjust the input levels of the alpha channel of your selection. To do this, start with your selection, then:

  • Colors menu > Levels... > Adjust Color Levels window:
    • Channel: Alpha
    • Under the Input Levels section:
      1. Optional: click the black eye-dropper, then click an area of your selection that you want to be completely transparent. (Or skip this step and just leave it at zero.)
      2. Click the white eye-dropper, then click an area of your selection that you want to be completely opaque.
    • Click OK.

Gimp Color Levels window

This sets the opacity of the entire selection so that the area selected in #1 becomes completely transparent, the area selected in #2 becomes completely opaque, and the transparency of everything in between is scaled proportionally.

Before:

Before

After:

After

Too long; don't read

Here's an explanation of what the above process does.

Alpha represented as grayscale

When an image's transparency (or alpha channel) is represented graphically, it is represented as a grayscale image:

  • Black areas represent pixels that are completely transparent.
    • That is, pixels with grayscale value 0 (black) represent pixels with alpha = 0/255 (0% opacity).
  • White areas represent pixels that are completely opaque.
    • That is, pixels with grayscale value 255 (white) represent pixels with alpha = 255/255 (100% opacity).
  • Gray areas represent pixels that are somewhere in between.

(Assuming the alpha value is an 8-bit number, from 0 to 255.)

Using Gimp's Color Levels to adjust alpha range

In Gimp's Adjust Color Levels window, it shows a histogram of the selection's lightness/darkness levels – that is, it shows a distribution of how many pixels in the selection are at each lightness/darkness value.

before histogram

In our case, we choose only the alpha channel, to adjust the lightness/darkness levels of the grayscale "color" that represents the selection's alpha channel only. The histogram above shows the alpha channel of the "before" image, and from this, we can see that it is composed of the following:

  • A spike of nearly 0% opaque pixels at the left end of the graph.
    • These pixels are nearly black in the alpha channel's "grayscale".
    • (Probably the four corners.)
  • A spike of approximately 50% opaque pixels in the middle of the graph.
    • These pixels are a medium shade of gray in the alpha channel's "grayscale".
    • (Probably the central area of the circle.)
  • A small band of pixels that range from ~0% to ~50% opacity between the two spikes.
    • In the alpha channel's "grayscale", these pixels range in shades of gray, from nearly black to the medium gray in the middle.
    • (Probably the gradual fade-out around the outside of the circle.)
  • Above ~50% opacity, there aren't any pixels.
    • So in the alpha channel's "grayscale", there aren't any white pixels, nor any pixels lighter than the medium gray in the middle.

So what we want to do is to take all the pixels in the left half of the graph and "stretch them out", so that they are distributed across the entire width of the graph from 0% opacity at the left end (value = 0 or "black") to 100% opacity at the right end (value = 255 or "white") – but we want to do it proportionally, so that the graph maintains approximately the same shape after we stretch it out. To do that, we can easily use the black/white eye-droppers under the Input Levels section:

  1. Using the black eye-dropper, we pick a pixel from the image – a pixel with an existing alpha value that we want to be scaled down to 0 (completely transparent).
    • In this case, this step isn't necessary, because the alpha channel already has values all the way down to 0 – we don't want the distribution to be stretched in that direction.
  2. Using the white eye-dropper, we pick another pixel from the image – a pixel with an existing alpha value that we want to be scaled up to 255 (completely opaque).

After we click OK to apply the change, we should see the desired effect in the selection. If we again open the Adjust Color Levels window and choose the alpha channel, we can look at the new distribution in the histogram:

after histogram

So we can see that the selection's alpha channel has been "spread out" to take up the entire range of alpha values from 0 to 255 – i.e. the opacity goes all the way from 0% to 100% – and has roughly the same proportion (relative distribution) throughout its occupied range as it did before, so that the "fade out" around the outside is still smooth from inside to outside as it was before.

1

Changing a transparency is done by editing the layer mask.

  • You create the layer mask with Layer>Mask>Add layer mask
  • If you only want to increase the transparency of some parts initialize the mask to white. What is white in the mask will have the initial opacity, and black will be fully transparent.
  • If you want full control, use the Transfer the layer's alpha channel. White will be fully opaque, and black will be transparent.
  • You can tell if you are editing the mask or the layer by looking as the bottom of the image window, next to the zoom indicator. It will either say {layer name} or {layer name} mask. You can switch between the two by clicking on their preview in the Layer list, or using Layer>Mask>Edit layer mask
  • The mask is a greyscale image that can be edited with the paint tools (brush, bucket, etc...) or any color tool such as Curves, Levels, and Brightness-Contrast, but also other tools and filters (you can render plasma on it, for instance).
  • The selection applies to the tools when editing the mask. The selection being global to the image, you can use on the mask a selection you obtained elsewhere (by editing the layer itself, for instance, or another layer).

For example, to make a partially-transparent area completely opaque in the middle while proportionally increasing the opacity of existing feathered edges:

  1. Activate the layer and add a layer mask to it, initializing the layer mask to "Transfer layer's alpha channel".

    • Layer > Mask > Add Layer Mask > Transfer layer's alpha channel
  2. Make sure the layer mask is activated for editing.

    • Layer > Mask > ✓ Edit Layer Mask (selected)
  3. Select the area of the layer where the transparency is to be modified.

  4. Use the "Levels" tool to automatically scale the selection in the layer mask proportionally from black to white (thereby scaling the selection's transparency from fully transparent to fully opaque).

    • Colors > Levels > Auto
1

If your goal is to adjust the alpha levels only, while keeping colors and relative opacity, do this:

  • Create a selection. For example, select by color with a threshold
  • Colors > Levels
  • Select Channel: Alpha
  • Adjust the output sliders. The image will be adjusted immediately. For example, to decrease relative opacity, grab the slide the solid white triangle left.

Tested in gimp 2.10.8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.