how can I add a transparency gradient in a grayscale to an image which already have background transparent?
For example: white color -> 70% transparent
gray -> 40% transparent
etc -> etc

Thanks
Code: Select all
> convert 2mgnsdh.png -negate tmp.png
> convert -size 176x202 'xc:#F6F6F6' png:- | convert - tmp.png -alpha off -compose CopyOpacity -composite -negate PNG32:target.png
Please clarify. You are not explaining this very well.For example: white color -> 70% transparent
gray -> 40% transparent
etc -> etc
Code: Select all
convert 2mgnsdh.png \
\( -clone 0 -alpha off +level 10%x70% \) \
\( -clone 0 -alpha extract \) \
\( -clone 1 -clone 2 -compose multiply -composite \) \
-delete 1,2 \
-alpha off -compose copy_opacity -composite result.png
See246246 wrote:Thank you, Fred. My first trial was to create 100%x0% one of your script step by step. Hope your script is the answer of the original question.
Today I learned a lot from you using -clone. I really appreciate some experts like you are here.
Code: Select all
convert 2mgnsdh-CMYK.tiff \
\( -clone 0 -channel K -alpha off +level 100%x0% \) \
\( -clone 0 -alpha extract \) \
\( -clone 1 -clone 2 -compose multiply -composite \) \
-delete 1,2 \
-alpha off -compose copy_opacity -composite result.tiff
This is not a good way to convert to CMYK. You should use profiles. Also the -colorspace CMYK, if you do it that way, needs to be after the input image.convert -colorspace CMYK 2mgnsdh.png 2mgnsdh-CMYK.tiff
Code: Select all
convert 2mgnsdh.png -colorspace CMYK 2mgnsdh.tif
convert 2mgnsdh.tif \
\( -clone 0 -alpha off +level 10%x70% \) \
\( -clone 0 -alpha extract -negate \) \
\( -clone 1 -clone 2 -compose multiply -composite \) \
-delete 1,2 \
-alpha off -compose copy_opacity -composite result.tif
Code: Select all
convert 2mgnsdh.tif \
\( -clone 0 -alpha off -channel K +level 10%x70% +channel \) \
\( -clone 0 -alpha extract \) \
\( -clone 1 -clone 2 -compose multiply -composite -negate \) \
-delete 1,2 \
-alpha off -compose copy_opacity -composite result.tif
Thank you very much! This is what i missed and confused me.fmw42 wrote:IM seems to have -alpha extract in CMYK negated. However, I am not that used to processing in CMYKA, so perhaps there is another reason (like CMYK without profiles typically displays as a negated version of RGB and needs to have a negate somewhere.
At a first glance, it seems to worked but all alpha values are set to the same value, except for the original background color. (IM 6.9.1.9 Q16 Windows but I call it from Cygwin bash, so syntax is same.)fmw42 wrote: But by negating the extracted alpha channel, the following works fine for me on IM 6.9.1.9 Q16 Mac OSX.
Code: Select all
convert 2mgnsdh.png -colorspace CMYK 2mgnsdh.tif convert 2mgnsdh.tif \ \( -clone 0 -alpha off +level 10%x70% \) \ \( -clone 0 -alpha extract -negate \) \ \( -clone 1 -clone 2 -compose multiply -composite \) \ -delete 1,2 \ -alpha off -compose copy_opacity -composite result.tif
Yes, I see one transparent color. But when compare with RGB case with your original script,fmw42 wrote:I still get a transparent CMYK tiff as the result of my commands above. Perhaps you are missing the one transparent color in the histogram of the result.