I want to watermark an image, so I used compose multiply, but for some reason it doesn't work as expected.
The command:
magick image.jpg over.png -compose multiply -resize 2048x2048 -gravity center -quality 65 -strip -composite out.jpg
The over.png get inverted first and then applied??
If use the same command with and older version of Imagemagick (x32 6.7.6-1 2012-03-17 Q16) I get the expected results.
This was tested with x64 ImageMagick 7.0.5 Q16 under Windows 10.
Ah it seems I can't post all the images.
After a lot of research, turns out it's an artifact of one of the images being a JPEG in CMYK colorspace.
Very weird, but there you go.
Adding '-profile sRGB.icc' to the line should take care of it.
FYI your syntax is not proper. You have separated -compose multiply and -composite with -resize. You should do it this way with nothing between them.
magick image.jpg over.png -gravity center -compose multiply -composite -resize 2048x2048 -strip -quality 65 out.jpg
As you said there will be issues if your input JPG is CMYK and your png will always be sRGB. So you do need to convert the CMYK to sRGB before processing.
Related
I wish to run the following four operations on each of a large number of files in a directory. Is there a more efficient (faster) way of doing this? Where me.png is one of the files.
composite -compose change-mask background.png me.png me.png
convert me.png -background blue -flatten me.png
convert me.png -transparent blue me.png
convert me.png -quality 95 me.png
Use convert in place of composite in ImageMagick and then you can chain all your commands.
convert me.png background.png -compose change-mask -composite -compose over -background blue -flatten -transparent blue -quality 95 me.png
See https://legacy.imagemagick.org/Usage/compose/#changemask and https://legacy.imagemagick.org/Usage/compose/
Also note that -quality for PNG is not the same as that for JPG. It is not in the range 0 to 100 as for JPG. See https://imagemagick.org/script/command-line-options.php#quality
I'm trying to convrt RAW image to PNG with Imagemagick.
Imagemagick version I'm using is 6.7.8-9.
The RAW image want to convert is:
https://drive.google.com/file/d/1V1c-ytjkLaCM3KbAc6Yxj2nfWzNkYohc/view?usp=sharing
My client gave me a big RAW image which contains more than 1000 RAW images and it is generated from Dicom. Firstly, I cropped just one image with the command (crop command did not work somehow, so used convert):
convert -size 512x512 -depth 16 UYVY:original.raw result.raw
result.raw appears good on ImageJ.
Now, I have no idea how to get PNG from it.
I tested some commands:
This one generated a very bad quality:
convert -size 512x512 -depth 16 gray:result.raw result.png
This one gets green-ish image:
convert -size 512x512 -depth 16 uyvy:result.raw result.png
If I open result.raw on ImageJ and save as PNG, it works perfectly.
I got an answer from Imagemagick community. Firstly, below code to get the first image from the original raw was wrong.
convert -size 512x512 -depth 16 UYVY:original.raw result.raw
This is the correct way (512*512*2bytes=524228)
head --bytes 524288 original.raw >firstimage.raw
Then convert to PNG:
magick -size 512x512 -depth 16 gray:firstimage.raw -evaluate AddModulus 50% -auto-level x.png
Here is another way in ImageMagick that I think is more intuitive to your signed raw data. I simply specify the data is signed using -define quantum-format=signed. Then stretch the result to full dynamic range using -auto-level.
convert -size 512x512 -depth 16 -define quantum:format=signed gray:original.raw -auto-level result.png
If using ImageMagick 7, then replace convert with magick.
I am converting many 3D textures with imagemagick for a video game. My source files are png, my target files are png, too. But I notice that whenever the alpha channel drops to 0.0 my color information are gone (and I need them). I just want to scale all channels as they are. I guess there is a small switch that fixes that problem, but the deadline is near and I cannot find anything about that.
Simple command to reproduce this:
convert source-with-alpha.png -scale 2014 target.png (I also tried -resize and it also didn't work).
Doing just convert source-with-alpha.png target.png works fine though (but has no scaledown).
Thank you for your help.
I guess ImageMagick is trying to optimise something but not sure what/why. Maybe the idea is that if something is transparent you can't see it, so we might as well make it black so it compresses well.
Anyway, try separating the channels so they are all just treated as independent channels, then resizing and recombining:
convert input.png -channel RGBA -separate -resize XxY -combine result.png
I am not sure I understand your problem. I have no issue resizing a transparent PNG image with ImageMagick 6.9.10.28 Q16 Mac OSX with libpng 1.6.36. Perhaps you need to upgrade one or both.
Image:
Make white into transparent:
convert logo.png -transparent white logot.png
Resize it:
convert logot.png -resize 25% logot_small.png
I tried Mark Setchell answer with two different versions of Windows imagemagick but I still have this issue.
RGB becomes 0 if alpha is 0 when resizing.
A workaround was to add alpha a little bit so it becomes non-zero:
magic.exe input.tga -channel a -evaluate add 0.2% -channel RGBA -separate -filter Quadratic -resize -resize XxY! -combine result.tga
or also (same result)
magick.exe ( input.tga -alpha off -filter Quadratic -resize XxY! ) ( input.tga -filter Quadratic -resize XxY! -alpha extract -evaluate add 0.2% ) -compose Copy_Alpha -composite result.tga
("-filter Quadratic" is optional)
Post one of your tga files so we can test with it. What is your ImageMagick version? There should be no need for any switch. This works fine for me on IM 6.9.10.65 Q16 Mac OSX.
Make a transparent TGA:
convert logo: -transparent white logo.tga
transparent tga image
Resize by 50%
convert logo.tga -resize 50% logo2.tga
resized transparent tga image
I'm trying to combine some operations using ImageMagick's magick CLI, specifically two operations that resize/scale the image, a random one that does -resize and a bunch of other stuff, plus the answer from this question (Average image color excluding transparency with Imagemagick).
The naive "mix everything together" doesn't work:
magick image -resize 10x10 ... -scale 1x1! -alpha off -format "%[pixel:u.p]\n" info:
...as I get an answer of "black", because this is obviously ignoring my image and using a blank image instead.
I've also tried with subimages (using \( ... \)) but that has the same problem
The following command works fine for me on ImageMagick 6.9.10.16 Q16. What is your ImageMagick version and what other commands do you need in the command line. You only show ...! What else is there? Also can you post your image? You cannot just put "image" in your command line. You have to specify the actual image file and possibly the path to it.
Input:
convert logo.png -transparent white -resize 50% -scale 1x1! -alpha off -format "%[pixel:u.p]" info:
srgb(100,82,99)
Same with IM 7.0.8.16 Q16 HDRI:
magick logo.png -transparent white -resize 50% -scale 1x1! -alpha off -format "%[pixel:u.p]" info:
srgb(100,81,99)
The slight difference is likely a difference from precision with IM 6 (non-hdri) and IM 7 (with hydra).
I have images where I would like to make the background transparent, remove the shadow and remove the product reflection.
So what I want to do is
Remove reflection
Remove shadow
Remove background
Test image
In Imagemagick 6, you can threshold the image and get the bounds of the black area. Then crop the original to those bounds.
convert image.png -threshold 50% +write image_thresh50.png -format "%#" info:
229x367+39+0
convert image.png -crop 229x367+39+0 +repage image_cropped.png
If using Imagemagick 7, change convert to magick.
Is this what you want?
To follow up on Bonzo's comment, in Unix ImageMagick 6, I could do:
cropvals=$(convert image.png -threshold 50% +write hAfUS_thresh50.png -format "%#" info:)
convert image.png -crop $cropvals +repage image_cropped.png
And in Unix, Imagemagick 7, I could do:
magick image.png \( +clone -threshold 50% -set option:cropvals "%#" +delete \) -crop "%[cropvals]" +repage image_cropped2.png
The reason I did not post these was because I did not know what OS/Platform the OP was using. It always helps when asking questions about Imagemagick to post its version and the platform it is run on.
Sorry I do not know how to do this in Windows syntax