2

I have an image that is a logo; a word written in a single solid color but the edge pixels of the letters originally had some transparency

The original was lost and now all I have is a version of it that has a white background. This image is thus predominantly either white (RGB html code #FFF, say - appreciate it would be #FFFFFF but using 3 characters for brevity/clarity) or pure red (#F00, say) but the edges of the letters have a band of pixels that are somewhere in between, such as "very white reds" #FEE or #FCC down to "very red reds" like #F22 or #F11

I wonder if there is a process that can paint the whole image as red #F00, but have an alpha component that is "how proportionally close to white the pixel was" or said another way "where the pixel color falls in the range #F00 to #FFF, determines how transparent the red needs to be (when laid on white) to look like the pink it does now"

I know how I'd do it if I had to code it up myself in C# (basically the maths of the above, to work out where the G and B values fall in the range and use that as the alpha component percentage), but is there anything out there technique wise that can "find and replace my red-with-white pixels" with "their equivalent red-with-transparency pixels" ?

2
  • Is there something which precludes recreation where you can control everything as opposed to trying to work around existing inferior image issues?
    – Scott
    Sep 30, 2020 at 19:10
  • It's a good call - I don't have the font (or even know the font), or have a reasonable image editing software on this computer. Part of the word is stylized into a sort of logo by an overlay of letters and it looks like some of the letters have been manipulated (the dot removed from the i, unless it's part of the font/a smaller uppercase I amid a lowercase word) so it would be a bit more work to recreate it.. My first thought was thus to see if someone could say "yeah, if you write imagemagick .... into a command prompt it'll proportionally replace all the white" but it's a good backup plan!
    – Caius Jard
    Sep 30, 2020 at 19:21

2 Answers 2

1

I stumbled upon this superuser post that seemed related and was able to make the GIMP instructions work reasonably well

  1. Open the image in GIMP 2.10
  2. Right click the image and choose Layer >> Transparency >> Color-to-alpha

The default white choice was nearly exactly the effect required, though the red appeared slightly transparent. I was able to make it less so by adjusting the Opacity Threshold down to about 0.888

The edge pixels of the letters were acceptably transparent (and I could probably mess with this more, but for the purposes I require it probably won't be necessary - it's just to stop it looking like it has a halo if laid on e.g. black)

enter image description here

(Resulting transparent PNG on white, After process in GIMP and Before I started I'd succeeded in removing pure white but still had pink pixels)

All in, surprised how click n easy it was! Any tips for improvement of the technique gratefully received..

1

This is a really interesting question. And will be a followup from this one

Part 1:

How to make a given color a bit darker or lighter?

I will not address how to mask properly an aliased border, I will talk about colors and opacity components.

Part 2:

Let's explore how theoretically the colors will respond as transparent over a white or black background.

  1. Take your base color

  2. Saturate it to the maximum value. This will make at least one of the RGB components to zero, and one of the remaining components full 255.

  3. Take the original value of the lowest RGB color. This is the white component, or in other words, the transparency if it is against a white background.


  1. If the color is darker the value is the difference between the maximum RGB value and 255. That would be the value of transparency against a black background.

  2. If you have a gap on both, top and the bottom value, those would be the proportion between black and white, in other words, gray background.

enter image description here

Your Answer

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

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