imagemagickimagemagick-convertdmg

How do I use Imagemagick to add a background to png with 1% opacity


I want to convert a png with a transparent background to one with a background with 1% opacity.

I want to do this because files within a .dmg window are only selectable/draggable, if there is a background to the file image.

I would like to do this using the cli convert function from Imagemagick.


Solution

  • You question is not very clear to me.

    If the following is not what you want, then please explain in more detail and/or post your input image.

    Lets assume you have only binary transparency, i.e, part fully transparent and part fully opaque, such as the following where the white area has been made transparent:

    enter image description here

    Here are the alpha value summaries of the original.

       Alpha:
          min: 0  (0)
          max: 255 (1)
          mean: 42.2975 (0.165872)
          standard deviation: 94.8515 (0.371967)
          kurtosis: 1.22756
          skewness: 1.79654
          entropy: 0.648175
    

    To make the fully transparent part 1% opaque and leave the fully opaque part unchanged, you could do the following in ImageMagick, namely, add 1% to the alpha channel. This makes black (0) go to 1% (3) and clips white so that it stays at 255.

    convert logot.png -channel a -evaluate add 1% +channel logot2.png
    

    enter image description here

    You will have to extract the images to see the transparency.

    Here are the alpha value summaries afterwards, where min of 0 is now min of 3. The (0.0117647) is the value in the range 0 to 1 or equivalently 1.17647%.

    Alpha:
      min: 3  (0.0117647)
      max: 255 (1)
      mean: 44.7998 (0.175686)
      standard deviation: 93.7356 (0.367591)
      kurtosis: 1.22756
      skewness: 1.79654
      entropy: 0.648175