I want to draw a circular gradient mask on an image, so that the image starts to fade at the outside of the circle with radius R, and fades to white with radius r < R. Is there a way to do this + how?
Example source image: (not the real one I'm trying to work with, but it doesn't matter)
If I do
convert flag1.png -fill white -draw "circle 400,234 200,200" flag2.png
then I get this:
In gimp I an do something like this with a radial gradient in another layer; my attempt looks crappy but this is vaguely what I want, except that it's not a smooth transition at the circle boundary, and my poor hand-eye coordination means I didn't get it centered:
Hmm: I muddled my way (via http://www.imagemagick.org/discourse-server/viewtopic.php?t=16692 ) to
convert flag1.png -size 800x468 radial-gradient:black-white -compose copy_opacity -composite flag3.png
which gives me something that's close to what I want with r=0 (never really completely fades out except at the very center); is there a way to expand to a white hole that fades out to a larger hole? And what does -compose copy_opacity -composite actually do?
Not sure what you are looking for exactly, but you could experiment with the percentages in this:
convert flag.png \( -size 800x468 radial-gradient:black-white -contrast-stretch 60%x0% \) -compose copy_opacity -composite flag3.png
The part in parentheses makes a black and white circle, and the -compose copy_opacity -composite part adopts that black and white circle as the alpha/transparency layer of the original flag image.
The parentheses ensure that the contrast stretch is only applied to the alpha/transparency layer and not the original coloured image.
Related
This is not a finding edge problem but I am trying to find the background color of the image, in order to find it, I am trying to get the edge of the image and guess the best color.
In order to do so, I want to remove the center of the image and just get image like a frame with transparent center.
Is it possible through ImageMagick?
For example
If want
Try this tested on Windows with IM V7:
magick "input.png" ( -size 200x200 xc:black ) -gravity center -compose DstOut -composite "output.png"
Takes the original photo, creates a rectangular mask, places it over the middle of the image and "cuts" out the rectangle
If the input is not a png ( for instance a jpg ) you will have to do some work setting the alpha channel
EDIT: This seems to work for both jpg and png images
magick "input.png" -alpha on ( -size 200x200 xc:black ) -gravity center -compose DstOut -composite "output.png"
I'll offer a simple variation on Bonzo's solution. This command allows you to specify in pixels the amount of edge you want to keep...
magick input.jpg -alpha on -bordercolor none -background none ^
( +clone -shave 24 -border 24 ) -compose dstout -composite output.png
It reads the input image, sets the alpha "on", and sets the border and background colors to "none".
Then inside the parentheses it makes a clone of the input image, shaves off the amount you want to retain around the edges, then adds that amount back as a transparent border all around. That will be the mask.
Then after the parentheses use a compose method of "dstout" to composite that mask onto the input image, which results in a transparent "hole" in the image with your specified amount of the original edge retained.
If you want to keep different amounts from the vertical and horizontal edges, specify those amounts in the shave and border operations...
... -shave 24x32 -border 24x32 ...
If you're using IMv7 you can even use FX expressions to specify the widths...
... -set option:v1 %[fx:(w+h)/2*0.1] -shave %[v1] -border %[v1] ...
The command is in Windows syntax using IMv7. Change "magick" to "convert" to use it with IMv6. To make it work in *nix you need to change the continued-line caret "^" to a backslash "\" and escape the parentheses with backslashes "\(...\)".
I want to generate an image out of 3 images. One of these images is the background, one the shape mask and one the color of the shape.
Here are the images:
shape.png
(transparent background, white circle in the middle and black circle inside and gray circle inside the black one)
shapecolor.png
background.png
The background.png should be the overall background. On top of that is the shape and all white parts (and also the white in the gray parts) should be in the color of shapecolor.png
I used simple mono color images to make it easier but I use some textures in reality ^^
I have no idea how to solve this problem in Imagemagick, the tool is very powerful and the documentation is not so easy to understand. Tried to solve this for 3h, but did not get the result, which should look like this:
Can anyone help please?
Here is one way to do it in Imagemagick. In the second line, extract the alpha channel from omg.png and save it in an mpr: in-memory image and then delete the clone. Then I use the mpr: image later in the last step.
convert red.png img.png \
\( +clone -alpha extract -write mpr:alpha +delete \) \
-compose multiply -composite \
green.png +swap mpr:alpha -compose over -composite \
result.png
I've got a PNG image with transparency:
original.png
Now I want to use ImageMagick to apply a diagonal gradient to its alpha channel. I mean so that its opacity remains in the top left corner, and gradually fades out to completely transparent in the bottom right corner. Like this:
result.png
So basically I want to generate a gradient, and use that as a mask for the image. But the image already has an alpha channel (transparency) of its own. Here's a visualisation of what I'm trying:
(original and result here displayed on checkerboard for visiblity, but I mean actual transparency)
I think I understand how to generate a diagonal gradient (the barycentric gradient command is very useful for this). But this creates a gradient in the color channels i.e. a colored or grayscale gradient. Whereas I want to apply the gradient on the alpha channel.
From the IM manual I understand the -compose CopyOpacity operator could be used for this. However this seems to copy the alpha from the mask on to my image. I need to "apply" this gradient color on my existing alpha channel, so basically I need my image's alpha channel to be multiplied by the grayscale color from the gradient image.
What would be the correct IM command line to perform the operation displayed above?
Here is one way you could do it:
convert tree.png -write MPR:orig -alpha extract \
\( +clone -colorspace gray -fx "1-j/h" \) \
-compose multiply -composite -write alpha.png \
MPR:orig +swap -compose copyopacity -composite result.png
The -write alpha.png can be omitted - it just shows the alpha layer for debugging and illustration purposes.
The MPR is just a temporary copy of the original image that I hold in memory while I am dinking around with the alpha channel and which I bring back near the end. The gradient in the alpha channel is generated by the -fx and I made the colorspace gray first so it only has to run once, instead of three times.
If you knew the dimensions of the tree image up front, you could replace the part in parentheses with:
-size WxH gradient:black-white
but I don't know the dimensions up front and I don't want a second convert command to get them, so I basically clone the original image's alpha channel to get a canvas the right size and fill it in with -fx.
I've got one background image: sky.jpg
And two transparent PNG images: gradient.png and tree.png
Now I want to draw the two images on the background with a perspective distortion, like this:
The destination coordinates of the two images are, in clockwise order (starting top left) :
gradient: 62,129 421,218 383,458 147,548
tree: 445,100 765,47 698,368 529,396
I cannot figure out how to start with one image (in this case the sky background) and then take another image and draw that with perspective distortion to specific destination coords within the background. Also doing this with more than one image at a time, within one convert command, troubles me.
For example, when I start with just one image (the gradient) and try this:
convert sky.jpg \( gradient.png -alpha set -virtual-pixel transparent \
+distort Perspective "0,0 62,129 255,0 421,218 255,255 383,458 0,255 147,548" \) \
-compose src-over -composite result.jpg
It gets correctly warped (so the coordinates are relatively correct) but it's drawn in the top left corner, not at the coordinates I specify.
Also I'm a bit unsure if my usage of -compose and -composite is correct (I took this from various IM manual examples).
One other thing that is unclear to me: in case of the 256x256 image, should I use 255,0 and 255,255 and 0,255 as the corner coordinates, or 256,0 and 256,256 and 0,256 ?
Any IM experts who can shed light on these issues?
Add a -geometry just before the -composite like this:
convert -size 800x600 xc:black \( -size 300x200 xc:red \) -geometry +90+10 -composite result.png
I'm trying to take an image, blur it with a 10px radius (both -blur and -gaussian-blur should work fine), then give it a 50% opacity, and finally overlay the blurred transparent image with the original. Here's what I've got so far:
convert sample.png \( sample.png -gaussian-blur 10 -matte -channel A
-evaluate set 50% \) -composite dreamy.png
Here's the original image:
And here is what it should look like after the effect is applied:
However, what I get with the command above just looks very similar to the original. Anyone have any ideas how to achieve the effect I want? If I do what I originally described in an image manipulation program, I get the desired effect, so something is probably wrong with the command I'm using.
Edit:
-adaptive-blur seems to get me closer to the desired effect, but still I'd like to use -blur.
Edit 2:
convert round-face-winslet.jpg \( +clone -blur 0x10 \) -compose Screen -composite round-face-winslet_soft.jpg
...gets me yet closer to the result, but no matter what kind of -compose method I choose, the result still does not look like the desired image. It's either too light or too dark. What should be a simple 50% opacity blended with the underlying original picture, for some reason doesn't want to work...
I think the effect you are looking for can be found in the ImageMagick compose examples in the "Softened Blurring" section.
convert face.png -morphology Convolve Gaussian:0x3 face_strong_blur.png
convert face.png face_strong_blur.png \
-compose Blend -define compose:args=60,40% -composite \
face_soft_blur.png
Looks like this:
An older tutorial on this technique (here) suggests lightening the blurred layer and blending in Multiply mode. I expect that darkening the blurred layer and blending with Screen would also work. Don't use a standard 50/50 blend - it doesn't have the same glowing appearance.
In your sample, the shadows of the processed image are lighter. Multiplying can only make an image darker, so I'm guessing they took the darken-Screen approach.