ImageMagick ignores my alpha channel and lowers the bit depth - image-processing

Here's the image I'm working on:
Here's the MS_DOS command line:
convert "IM_Effect_Smoke_problem.png" -background transparent -crop 64x64+0+64! "IM_Effect_Smoke_problem_crop.png"
The problem is that ImageMagick reduces the color depth to 8 bits and ignores or destroys the alpha channel.
Can anyone tell me how to fix this? Thanks!!!

Testing the command with ImageMagick 6.6.9-7, on Ubuntu, preserves the alpha channel. Maybe there the issue is with the version of ImageMagick you're using if you're sure the alpha channel is removed.

Related

Imagemagick convert command adds noise to the png-to-png export result

I'm trying to convert an not-optimized PNG to an optimized version using ImageMagick's convert command:
convert -colors 40 test.png test-optimized.png
The problem is however that the convert operation adds weird noise. I want multiple levels of alpha transparency in my export, which convert seems to offer, but without all the noise, and the file size should stay low. I wouldn't expect to need more than 16 different colors to optimize the original image with some levels of anti-aliasing in both the blue area and the transparent area. Any idea's? It almost looks like it is adding something like a JPEG compression or something (which of course doesn't add transparency). I tried already with different -anti-aliasing and -alpha options.
Source
Optimized
This question can be closed: the problem was a version issue.
The problem occurs with:
ImageMagick 6.9.0-0 (as reported by Mark Scetchell in the comments)
ImageMagick 6.9.1-0 Q16 x86_64 2015-04-06
But no longer with:
ImageMagick 6.9.3-0 Q16 x86_64 2016-01-31
Thanks to Mark Scetchel and Glenn Randers-Pehrson for their input.

Prevent ImageMagick from using indexed colors?

I have some PNG images with transparency. However, whenever I do any operations with ImageMagick on the image (e.g. cropping), it changes some of the images to be "indexed" color instead of RGB. The images that change are ones where there happens to be fewer than 256 colors, but the conversion ruins the transparency.
From some research I found you can prepend a filename with png32: to force RGB, but that only works when using the convert command, not mogrify.
I can add -format png32 with mogrify, but that renames all the images to *.png32.
Supposedly you can do this:
mogrify -define png:format=png32 -format png *.png
But it doesn't work, the images are still indexed color not RGB. How do I force PNG32 with mogrify?
Your command should have worked, if you are using a recent version of ImageMagick (6.9.1-3 or later).
Earlier versions will work if you use the -format png32 option as you did, then run a script to rename them back to *.png.
According to the ImageMagick 6 change log, the "-define png:format=png32" option was added to ImageMagick at version 6.7.3-0, but a bug was introduced at version 6.8.9-0 that caused it to be ignored in certain circumstances; that bug was fixed in version 6.9.1-3.
So the answer to your question is to either work around the problem by letting mogrify rename your input files to *.png32, or to upgrade your ImageMagick to 6.9.1-3 or later.

ImageMagick 6.7.7 conversion from RGB PDF to CMYK PDF looks dark

I am using ImageMagick 6.7.7 on Ubuntu 14.04.2.
I am converting an RGB PDF to CMYK PDF and it looks dark. But it is working fine with ImageMagick 6.6.6.
I am using below command:
convert tp_rgb.pdf -verbose -density 300 -colorspace CMYK tp_cmyk.pdf
How can we fix that? Can any help me with this?
At version 6.7.6, ImageMagick started treating grayscale images without colorspace information as "linear" instead of "sRGB" by default, with the result that they looked darker. Later, the default was switched back to "sRGB" and a few related problems were fixed. Upgrading to version 6.8.9 or later will restore the original, expected behavior, where all images are handled as "sRGB" by default.

Converting a multi page pdf to multiple pages using a single command

I want to convert multi page pdfs into single page images efficiently.
I already know how to do this one page at a time with imagemagick. For example,
convert x.pdf[2] x3.jpg
will give me the 3rd page of the pdf as an image. So if I figure out how many pages are in the pdf using identify then I can loop through and convert all pages in the pdf to images. This method can however take a while. For example a 15 page pdf could take anywhere between 15-30 seconds.
According to answers that I have seen elsewhere (also on the imagemagick forums) the following imagemagick command should split a pdf into multiple images.
convert x.pdf x-%0d.jpg
but all this ends up doing is creating the first page named x-0.jpg
As an alternative I have tried using pdftk with the burst capability. The problem I faced there is that burst does not work in all cases. It does for some pdf's and does not for some others.
Any suggestions on how to improve things would help.
My OS is Mac OSX Lion but I do need this working on CentOS 6 as well.
You're missing the quantity of digits. Use:
convert x.pdf x-%04d.jpg
Where 4 means 4 digits will be show on the page count.
If you use Graphicsmagick on Debian or ImageMagick on macOS you probably have to add ADJOIN to your command.
So it should look like
convert x.pdf +adjoin x-%04d.jpg
When I tried to convert my multi-page pdf, the resulting image files had a gray background despite the pdf having a white background. (#John P commented on it on the accepted answer, but I couldn't get his comment to directly work for me.)
Here's what worked for me to make the background white:
convert -authenticate yourpassword -background white -alpha remove -alpha off -density 300 -quality 80 -verbose "Your file.pdf" "Your file.png"
My pdf had a password hence the authenticate.
You can see a summary of the options here:
-authenticate value decipher image with this password
-background color background color
-alpha on, activate, off, deactivate, set, opaque, copy", transparent, extract, background, or shape the alpha channel
-density geometry horizontal and vertical density of the image
-quality value JPEG/MIFF/PNG compression level
-verbose print detailed information about the image
More detail: https://imagemagick.org/script/convert.php
And the alpha remove option: http://www.imagemagick.org/Usage/masking/#alpha_remove
Ran into the same issue. Reinstall Imagemagick to work in Mountain Lion. If you use brew the simply
$brew unlink imagemagick
$brew install imagemagick

png to gif with transparency

I have a png image with some transparency. I would like to transform it to a gif image. I have tried imagemagik using convert myimage.png myimage.gif but transparency is not respected.
Any solution using linux commands? thanks
What you are doing should work out of box.
However, there's an important limitation of GIF as a format (not related to imagemagick). It does not support semi-transparency (alpha channel). Transparency in GIF is on/off (boolean).
Docs claim that the default behavior is to make pixels with (alpha<50%) fully transparent.
Depending on your image, you may achieve satisfactory results though. For example, by tweaking the threshold (code from ImageMagick docs):
convert a.png -channel A -threshold 15% a_no_shadow.gif
See more info on available options at:
http://www.imagemagick.org/Usage/formats/#gif

Resources