I've a png image containing transparent pixels and colored pixels (mainly white).
I'd like to transform all transparent pixels to white pixels and all white pixels to transparent pixels within a given rectangle.
My idea would be to
convert the white pixels to red
the transparent colors to white
and the red colors to transparent
. Here' s my code:
1) convert ldl_0.png -fuzz 10% -fill red -opaque white lx.png
2) convert lx.png -background white -alpha remove -alpha off lx2.png
However I can' t figure out how do I transform red colors to transparent. How do I do that?
Also how can I force to do this only within a given rectangle?
Thank You.
-----
Try this in ImageMagick. Negate the alpha channel and turn the whole RGB channels to white.
convert in.png -channel a -negate +channel -fill white -colorize 100 out.png
Related
I have a small icon GIF that I would like to change the color. All opaque GIF pixels should be replaced by this new color, but preserve transparency for the gif. Then I need to place that new colored GIF over a background map, all in one command line. Here is what I have, but it's not changing all gif opaque pixels. Attached is the GIF icon. (Edit: I know im only targeting the white here, but just can't figure out how to target ALL opaque pixels in the GIF)
exec("{$convert} {$map_image} \( {$map_icon} -fill orange -opaque white -geometry +1700+600 \) -composite map2.jpg ");
Use +opaque none to fill all non-transparent colors in ImageMagick. The +opaque means everything "but" that color.
convert grid.gif -fill orange +opaque none x.png
I have an image and I want to fill with some color (e.g. blue) parts of that image which are outside of a rectangle. Position of left upper corner and width/height of this rectangle relative to the left upper corner of the original image are known.
Here borders of the original image are in red and borders of the rectangle are in black. Blue area should be filled.
How can I do this? I tried to create a tmp image and use a mask but it seems to also fill transparent regions inside the rectangle which is not what I want.
Also, there is probably a way to do it without creating intermediate images? I'd be interested in both options though, because I'm not sure how requirements will change over time -- maybe in the future I'd have to apply some other shape (not a rectangle), so having a way to apply an arbitrary mask would be better in that case.
Example:
image:
coordinates of the rectangle (assuming x axis runs from left to right, y axis from top to bottom, with (0,0) being left-upper corner of the original image):
left-upper corner (117,-24)
right-bottom corner (1117,1676)
Find a colour that doesn't exist in the original image. Hint: use -unique-colors
Fill/draw the black image with that colour
Make everything that is not that colour blue. Hint: use -fill blue +opaque THATCOLOUR
The blue pixels are your mask
Not sure if I have understood you correctly, but here is what I get for the first part:
magick 7uZfM.png -alpha deactivate -fill yellow -draw "rectangle 117,-24 1117,1676" result1.png
And then the second part:
magick 7uZfM.png -alpha deactivate -fill yellow -draw "rectangle 117,-24 1117,1676" -fill blue +opaque yellow -transparent yellow result2.png
Ok, now with the original image showing through:
magick 7uZfM.png \( +clone -alpha deactivate -fill yellow -draw "rectangle 117,-24 1117,1676" -fill blue +opaque yellow -transparent yellow \) -flatten -background magenta result3.png
I have a bunch of PNG images (logos) that I want to convert to an all-white color pallet; basically I want to replace all non-transparent pixels with white pixels. Is there an easy way to do this in imagemagick?
You can do that in ImageMagick using -colorize.
convert input.png -fill white -colorize 100 output.png
It will preserve the transparent pixels and make everything else white.
im trying to delete the background with a batch process in pictures of products for an e-commerce site.
The problem is that the script also remove the white color in the inside of the product, leaving the product transparent in some areas..
For example:
Command:
convert *.jpg -set filename: %t -fuzz 5% -transparent white %[filename:].png
this is the best I can get..im ok with this result around the product, but I need that the white inside the product remains white and not transparent.
The problem with your current approach is that it doesn't respect boundaries, it is just applied globally, making all white pixels transparent regardless of their connectivity to the background.
Instead, you will get on better using a "floodfill" that only floods into areas that are within the fuzz distance of the top-left corner pixel.
So, I chose an unused colour of magenta so you can see what is happening:
convert product.jpg -fuzz 5% -fill magenta -draw 'color 0,0 floodfill' result.png
You would then follow that with the command to make magenta transparent like this:
convert product.jpg -fuzz 5% -fill magenta -draw 'color 0,0 floodfill' -transparent magenta result.png
Converting black and dark shades to transparent works fine with ImageMagick.
I even managed to perform a crop and resize in the same line.
convert input.png -background none -fuzz 45% -transparent black -flatten -crop 640x480+12+9 -resize 105% output.png
However, the input image also contains a number of almost white lines, which I also would like to convert to transparent in the output.
How do I go about that? Is it possible to do it within the same command line?
Sure, just add a second -transparent.
convert -size 512x512 gradient:black-white a.png # create initial black-to-white gradient
convert -fuzz 20% a.png -transparent black -transparent white result.png # lose 20% off black end and white end
Or, with extra fuzz...
convert -fuzz 40% a.png -transparent black -transparent white result.png