ImageMagic | JMagick | Transparent Image - imagemagick

Is there a way in Jmagick to make a png image transparent?
Input: A PNG image
Output: A transparent PNG image
I want the background of an image to be transparent.

Your question is quite unclear, but if you mean you want to ensure that a PNG image is saved with an alpha/transparency layer, then all you need to do is prefix the output filename with PNG32:. In the Terminal, that looks like this:
magick input.png PNG32:output.png
If you mean something else, please click edit under your question and clarify.

Related

Can the `cwebp` tool convert a specific color to transparent pixels in its output?

I have some source images which have a black background, and I would like to convert them into WebP images that have a transparent background.
I don't understand the talk about alpha channels from their documentation, so I am unsure if this is even possible with cwebp. I tried some guesswork with the arguments, but none worked.
The command I use for direct conversion from JPG to WebP is:
cwebp ./input.jpg -o ./output.webp
What would I need to add to this in order to get the black background from the input JPG to be transparent in the output WebP?
I think cwebp's options are mostly focused on compression with some limited other options for manipulating the image like cropping and sharpness.
To accomplish this task I would recommend image magick which is a general purpose image manipulation tool. that can remove the transparency, and then you can send that to cwebp.
imagick convert image.jpg -fuzz 2% -transparent black image.png
cwebp image.png -o image.webp

Compose image with mask image using ImageMagick

Suppose I have some image a.jpg and some other image b.jpg.
The desired output out.jpg should be obtained by copying all the pixels from b.jpg that are not black onto a.jpg, all other pixels shall remain untouched.
I tried using composite but had no success whatsoever.
EDITED TO ADD: A solution here can be quite simple and generic, but going forward, please remember to always include your version of ImageMagick and which OS or platform you're working on. There are some syntax differences that can make that important.
At the very simplest, using ImageMagick v6, you should be able to do something like this...
convert b.jpg -background none -transparent black a.jpg +swap -composite out.jpg
That reads in the B image, changes all the pure black pixels to transparent, then reads in the A image, swaps the images so they're in the right order, then composites the modified B image over the A image and writes the output.
You can add a fuzz value like "-fuzz 5%" ahead of the "-transparent" operation to expand the selection to include near-black pixels, also.
To use with IMv7 change "convert" to "magick".

How to change the depth of an image using imagemagick?

I have tried adding the option -depth 12 to the string
convert transparentPNG.png -resize 500x400 -background white -flatten -depth 12 png_small.jpg
The input file is a transparent png to which I'm adding a background and then changing the depth. But the depth remains the same as 8bits. I verified the same using the -verbose.
I'm not sure what could I be doing wrong here. I'm referring to the site link
The transparent input png file used for my test can be found here
Let me know if you have any questions on the tests i did. Hoping to get some tips.
A JPG can only be 8-bit, so your internal 12-bit image is converted back to 8-bit when you save the result.

Replace every color except a specific one in Imagemagick

Let's say I have a PNG image with some random colors in it, like this one:
The goal is to make every color in the image EXCEPT a specific color (like #FCFF00) with pure black (#000000). So for example, if I gave the code the above image, it would replace it with this:
How would I do this?
This would be the +opaque option.
convert YiCYA.png -fill black +opaque '#FC00FF' output.png

How to pixelate/blur an image using ImageMagick?

I want to pixelate and/or blur an image.
I've found the command for the blurring:
$convert image.jpg -blur 18,5 newimage.jpg
to work but I cannot blur the image any more.
And how do I pixelate the image? I couldn't find a sound example around the net.
Thx
To get a proper square pixellation, try:
convert -scale 10% -scale 1000% original.jpg pixelated.jpg
This worked nicely for me, gives a sort of cross between pixelating and blurring:
convert -resize 10% image.jpg newimage.jpg
convert -resize 1000% newimage.jpg newimage.jpg
You can be sure that the data cannot be retrieved, should that be important to you.
Changing the %ages will change the amount of pixelation/blur
I don't know anything about ImageMagick, but you can try resizing the image using bicubic to a much smaller dimension, then resizing the image back to a bigger one.
The trick works using .net's System.Drawing object.

Resources