I have this two pictures http://s29.postimg.org/6j5m4jyx3/frame_0.png and http://s14.postimg.org/zdfn4f84x/frame_2.png and I need to mix both into a new picture with first at back and second at front with opacity at 70%.
To do it, I have this commands:
convert frame-2.png -background transparent -alpha set -channel A -evaluate set 70% frame-1.png
composite -background transparent -gravity center frame-1.png frame-0.png frame-1.png
Result is like I want but transparency to frame-2.png is applied with a strange way. I don't understand why transparent background also get a "black" opacity http://s27.postimg.org/bst4fmnhv/frame_1.png
Result should be http://s28.postimg.org/pb1ee1egt/frame_1.png
Ok, solution is using
-evaluate Divide 1.5
instead
-evaluate set 70%
And with this way, transparecy is applied perfect :)
Related
I am trying to add a 10px red border to a transparent PNG using ImageMagick, while preserving any existing transparency that might exist within the image. Here is my source image:
If you download and view that image with an image viewer, you'll see that it has a transparent background.
According to everything I've read, the following Imagemagick command should add a 10px red border to the image:
convert input.png -bordercolor red -border 10 output.png
It actually does add the red border to the image, since the output dimensions are 20px larger in both directions. Unfortunately it also changes the background color of the image to red as well. Here is the output file:
I do not want the transparent area to be changed to red. I only want to add a red border around the transparent image.
I've tried using both ImageMagick version 6.9.10-23 (Ubuntu) and 7.1.0 (via CloudConvert API), with the same result. I've spent hours(!) trying to solve this.
What am I doing wrong?
I found the answer in this thread: https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=31843 . Here are the two money quotes:
So, "-bordercolor red -border 2" should create an opaque red image 2
pixels larger than the input, and composite the input over this. As
your input is "-size 100x100 xc:none", the result should be 102x102
opaque red pixels. You might think this is "pretty obviously
incorrect", but it is the documented behaviour.
and
Nevertheless, you can get it to work to have the transparent inside,
if you add -compose copy before -bordercolor red -border 2 in both the
current IM 6 and IM 7. This just may have to be the way to do it from
here on, if there is a good reason for the changed behavior.
Here is the command that produces the result I am after:
convert -background transparent -bordercolor red -compose Copy -border 10 input.png output.png
Here's an answer that fully preserves the transparency
convert input.png +write mpr:INP -alpha extract -morphology dilate disk:10 \\( +clone -fill Black -colorize 100 \\) +swap -compose CopyOpacity -composite mpr:INP -compose Over -composite output.png
From https://legacy.imagemagick.org/Usage/crop/#extent
Here is a simple way to do that in Imagemagick. Change the compose setting from over to copy.
Input:
convert logo_transp.png -compose copy -bordercolor red -border 10 logo_transp_border.png
Is it possible to set the alpha channel of an image according to a gradient with ImageMagick?
I'd like the pixels on the left border of an image to be 100% transparent, and the ones on the right border to be 100% opaque, and with the ones in the middle having progressively lower transparency values.
Or in a more general case - given a grayscale image, set the alpha channel of another image as a function of the B&W values (black = 100% alpha, white 0% alpha).
With ImageMagick you can use -sparse-color to apply a gradient only to the alpha channel to get the result you describe.
convert in.png -alpha set -background none -channel A \
-sparse-color barycentric "0,0 none %[w],0 white" +channel out.png
That command starts by activating the alpha channel and setting the background color to transparent. Then it uses -channel A to apply the following operation only to the alpha channel. The -sparse-color operation tells it to start with transparent at the far left edge, pixel 0,0 and graduate to opaque at pixel %[w],0. The %[w] means the width or far right edge.
Although there are many ways to accomplish the effect you've described, by using -sparse-color you can easily make the gradient start and end at any positions on the image without having to create any intermediate masking images.
Simple. You would use -composite CopyOpacity to set the alpha channel from a gradient mask.
Given I have the following images. image.png & transparent_mask.png
We can set the image transparency (where black is alpha, and white is opaque) by copying values from the mask image to the input image alpha channel.
convert image.png transparent_mask.png -compose CopyOpacity -composite output.png
I've got 2 versions of 1 image
Is it possible to get a transparent png file representing this watermark? Can ImageMagick do this?
SilverMonkey has the basic solution using Imagemagick. But the request was for a transparent PNG. So I will add a little bit more to his code to make it transparent by adding -alpha copy.
convert kitty2.jpg kitty1.jpg -compose minus -composite -auto-level -alpha copy watermark1.png
Here is another approach that makes a binary mask for the watermark by thresholding. But it leaves a lot of noise. So I use some morphology open to remove the noise and then some morpholgy close to try to fill in where the text is broken up. Then I add -alpha copy to make the image transparent. But the text is white and the original watermark was light gray. So I turn alpha off, multiply by 0.75 to reduce the brightness of the white letters to gray without affecting the alpha channel. Then turn the alpha channel back on.
convert kitty2.jpg kitty1.jpg -compose minus -composite -threshold 0.6% -morphology open diamond:1 -morphology close octagon:1 -alpha copy -alpha off -evaluate multiply 0.75 -alpha on watermark2.png
For more on morphology, see https://imagemagick.org/Usage/morphology/
You can achieve your goal by calculating the difference between both images (subtract the pixels of both images and calculate the absolute value). This will result in:
ImageMagick seems to be capable of image subtraction, look here:
The code:
convert image2 image1 -compose minus -composite result
I want to create a diff from two images, that can be applyed on top of first image, resulting on the same second image.
I'm trying to do like this:
convert -composite -compose difference img1.png img2.png img-diff.png
The resulting img-diff.png shows a black background where img1.png is equal to img2.png.
I want to generate the diff with a transparent background, to allow me to create an animation by combining it with the first image.
I think you need to add -transparent black before the output filename. You may, or may not, want to add a -fuzz 5% to make near black also become transparent.
So, in concrete terms, if you start off with these two images
and you then run this command:
convert 1.jpg 2.jpg -compose difference -composite -fuzz 5% -transparent black out.png
you end up with this (it shows transparent as white because SO uses JPEGs which can't show transparency).
I think the problem with your (valiant) attempt is that you need to set -compose first to tell IM how to compose the images before it actually goes ahead and does it with -composite and also you were missing the -transparent black part.
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.