I need to take a normal image:
and add a white, transparent overlay so it looks something like this:
Don't pay attention to the text on the converted image or the fact that it's a cropped version of the original. I need to simply convert the top to the exact same image, just with this white, transparent overlay. I also need it to be a cli command.
Updated Answer
This is even easier
convert house.jpg -fill white -colorize 80% result.png
Original Answer
Something like this maybe...
convert house.jpg \( +clone -fill white -colorize 80% \) -composite result.png
Related
I have a PNG image with a black shape on transparent background.
I need a white shape on a solid black background instead.
How can I achieve that with Imagemagick?
Image example:
I have this:
I want this:
The image you posted is not transparent. It has an opaque checkerboard background. However, if it was transparent, this Imagemagick command should work.
convert image.png -background white -flatten -negate result.png
If using Imagemagick 7, then change convert to magick
As #fmw42 said, your image is not a true PNG image. So for your image you can do:
convert input.png -white-threshold 0% -negate out.png
Which will give you:
Might be able to simply extract the alpha channel to a new image.
For example, let's create a transparent image.
convert -size 100x100 xc:transparent -fill black -draw 'circle 50,50 50,10' transparent.png
Now we can extract the alpha channel knowing that fully transparent is black, and opaque is white.
convert transparent.png -alpha extract output.png
I have two images and I want to crop a part of the first one, and paste it into the other one in a specific place using imagemagick. Also the crop part would be gray
I want this: http://imgur.com/3PomJ9k
But I got this: http://imgur.com/5XmhytN
I have tried:
convert source.jpg ( +clone -crop 240x270+595+140 -resize 112x146 -type Grayscale ) -geometry +10+200 -composite destiny.jpg
but as you see, it does not works as expected.
Although the crop part is cloned as gray, the whole first image is cloned too, but I need to keep in background the second image in color and the crop part in gray in front of it.
Some ideas?
From our discussion in chat, I think you need something along these lines - you may need to fiddle with the actual numbers but hopefully the concept is clear:
convert other.jpg \( source.jpg -crop 240x270+595+140 -colorspace gray -resize 116x150! \) -geometry +4+108 -composite result.png
we run a mogrify batch job like mogrify -path "WEBREADY\DONE" -layers merge -trim +repage -resize "1200x1200>" -define jpeg:extent=500kb -format jpg *.*
This works fine for images with a white background. But recently we saw a 2% error rate and discovered the error. Mogrify trims as expected only on the web the images is surrounded by white so this looks quite silly with grey-ish in corners.
THe solution would be to either
Detect the non-white background. And in that case -only- do not trim
Or to detect the background color (it is JPG) in top left corner and forst set this to an all white background.
Can this be done in my 1 command above for the commandline? (so find the grey background first and change it to white)
You can get the colour of the top-left pixel like this:
convert shirt.jpg -crop 1x1+0+0 txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (57311,57311,57311) #DFDFDF srgb(223,223,223)
So, it is #DFDFDF.
If you now try and replace that shade with yellow (I know you want white but you can't see that on here):
convert shirt.jpg -fill yellow -opaque "#DFDFDF" result.png
and you can now see the problem. The background is not uniform and its colour also appears in your shirt. If you add some fuzz, it makes it more pronounced:
convert shirt.jpg -fill yellow -fuzz 10% -opaque "#DFDFDF" result.png
Even if you try flood filling from the top-left, you still have to hope that there are no pixels in the edges of your shirt that are similar to that corner:
convert shirt.jpg -fill yellow -fuzz 5% -floodfill +0+0 "#dfdfdf" result.png
I have a series of images in PNG format that make up an animation.
I want to automate the process of cropping the excess transparency in the animation as a whole, so I need to find the unique smallest rectangular area such that, if every image were cropped to it, no opaque pixels would be trimmed from any image; then crop every image to this area.
IOW, the equivalent of making each PNG a layer in GIMP, doing "autocrop layer" on every layer, then "canvas size to layers", and reexporting every layer as a PNG again.
Is there a way to get mogrify or convert (or GIMP, for that matter, but I imagine in my case the number of images involved would take up too much memory to have them all as GIMP layers) to do this automatically?
If not, is there a scripting function that would return the autocrop rectangle for a given image, so I could check overlaps and find the smallest that would cover all of them, myself?
You can get the cropping box for an image like this:
convert input.png -format "%#" info:
245x114+4+2
So, in this instance it is 245px wide by 114px tall and offset [4,2] from the top-left corner.
So, to test the theory, let's make 3 images with transparent background and little red boxes to represent your content. I have added a black border just so you can see the extent on Stack Overflow's white background:
convert -size 200x100 xc:none -fill red -draw "rectangle 10,10 20,20" 1.png
convert -size 200x100 xc:none -fill red -draw "rectangle 180,20 190,30" 2.png
convert -size 200x100 xc:none -fill red -draw "rectangle 150,80 160,90" 3.png
So, I can get the cropping box for all 3 images combined like this:
convert [123].png -evaluate-sequence mean -format %# info:
181x81+10+10
And if I draw that on in blue:
convert result.png -stroke blue -fill none -draw "rectangle 10,10 191,91" -bordercolor black -border 1 result.png
I've a number of images with transparent pixels both inside the graphics and outside. One example is:
and
So now I want to fill only the internal transparent pixels (the ones within the black boarder), is there any batch processing way to do it? I tried imagemagick convert tool, but didn't figure out how to the the "selective" conversion.
Thanks for any help!
there are following ways how can accomplish that (it all depends on how the image is composed):
if you know the part you want to keep transparents starts at 0x0
You start by removing all transparency with something like http://www.imagemagick.org/Usage/masking/#remove
and then re-add the transparency using flood-fill starting at 0x0 http://www.imagemagick.org/Usage/masking/#bg_remove
You have more control over whats going on by using a transparency mask:
then you start modifying the mask (which is now only black/white), by coloringusing floddfill starting wiht 0x0 (i.e. with blue), replacing the black with white and then replacing all blue pixel with black (for color replacement see http://www.imagemagick.org/Usage/color_basics/#replace)
# the mask
convert original.png -alpha extract mask.png
convert mask.png -fill blue -draw 'color 0,0 floodfill' mask_blue.png
convert mask_blue.png -fill white -opaque black mask_filled_blue.png
convert mask_filled_blue.png -fill black -opaque blue mask_filled.png
# change transparent to skyblue
convert original.png -background skyblue -alpha remove -alpha off original_nontransparent.png
# apply the modified mask
convert original_nontransparent.png mask_filled.png -alpha Off -compose CopyOpacity -composite final.png
Note that this techniqe works only moderatly well with half transparent things (see http://www.imagemagick.org/Usage/antialiasing/#floodfill ).
For better results with half-transparency you might want to use different methods to "fill" the mask. You would i.e. just draw a shape instead of the two fill operations on the mask:
convert mask.png -fill black -draw "circle 40,80 60,60" mask_filled.png
this will fill the center, but keep the half transparency intact.
if you know the "center" is always trnsparent, you could also floodfill from the center.
Hope this helps