I have two tif images - input.tif and test.tif - and what I want to achieve is apply alpha channel of the first image to the second one. This is what I do now, using ImageMagick:
C:\Images> magick input.tif -alpha extract alpha.pgm
C:\Images> magick test.tif alpha.pgm -compose copyalpha -composite output.tif
When, however, I try to open output.tif, I get a message that the image is corrupt.
try adding -alpha off in your second command
C:\Images> magick input.tif -alpha extract alpha.pgm
C:\Images> magick test.tif alpha.pgm -alpha off -compose copy_opacity -composite output.tif
Or you can do it in one command as:
C:\Images> magick test.tif ( input.tif -alpha extract ) -alpha off -compose copy_opacity -composite output.tif
Related
I have to convert the pdf file (with more text) to images with different resolution.
I am executing the following commands:
width:1024px
convert -density 150 -antialias -resize 1024x -quality 80 "${inputFilePath}" "${outputFilePath}"
width:720px
convert -density 150 -antialias -resize 720x -quality 80 "${inputFilePath}" "${outputFilePath}"
width:320px
convert -density 150 -antialias -resize 320x -quality 80 "${inputFilePath}" "${outputFilePath}"
The generated images are not clear.
Can you help me to understand what I have to change?
Thanks in advance.
Increase your density to get better quality. -antialias will not help in your ImageMagick command. It is only used when adding new text. Put the density after convert and then put the input. Put your quality after the input and before the output. Use parenthesis processing with clones to generate all 3 results in one convert command.
convert -density 300 input \
\( -clone 0 -resize 1024x -quality 80 +write output1 \) \
\( -clone 0 -resize 720x -quality 80 +write output2 \) \
\( -clone 0 -resize 320x -quality 80 +write output3 \) \
null:
Is it possible to have one source and from that have 2 types of processed images with different configurations? (and not to read the source image twice)?
Something like
convert input.jpg -resize 300 output1.jpg -resize 600 output2.jpg
Sure, use an intermediate -write like this, and do the big one first:
convert input.jpg -resize 600 -write im600.jpg -resize 300 im300.jpg
Or, if you want to start afresh with each operation:
convert input.png \
\( +clone -resize 300 -write result300.jpg \) \
\( +clone -resize 600 -write result600.jpg \) null:
If using GraphicsMagick, I am not sure if there is a better way than the following:
#!/bin/bash
{ echo convert input.png mpr:orig;
echo convert mpr:orig -resize 300 result300.jpg;
echo convert mpr:orig -resize 600 result600.jpg; } | gm batch -prompt off
This is a slightly different version that only invokes convert twice:
#!/bin/bash
cat - <<EOF | gm batch -prompt off
convert input.png -write mpr:orig -resize 300 result300.jpg
convert mpr:orig -resize 600 result600.jpg
EOF
I have a command-line that outputs an image as intended but gives me an error on completion of convert: pixels are not authentic. Why could this be happening?
I am using ImageMagick 6.9.2-8 Q16 x86_64 2015-12-06 in Term2 on OSX El Capitan.
The command / output / error :
convert -verbose artwork.jpg -resize 1800x \
\( +clone -gravity center -background white -extent 2000x2000 \) \
\( -clone 1 displaceY.png -compose displace -define compose:args=0x5% -composite \) \
\( -clone 2 -gravity west displaceX.png -compose displace -define compose:args=5x0% -composite \) \
-delete 0--2 \( +clone alpha.png -compose copy_opacity -composite \) -delete 0 out.png
artwork.jpg JPEG 2952x2124 2952x2124+0+0 8-bit sRGB 911KB 0.000u 0:00.000
displaceY.png PNG 2000x2000 2000x2000+0+0 8-bit sRGB 109KB 0.000u 0:00.000
displaceX.png PNG 2400x2400 2400x2400+0+0 8-bit sRGB 104KB 0.000u 0:00.000
alpha.png PNG 2000x2000 2000x2000+0+0 8-bit sRGB 63.9KB 0.000u 0:00.000
artwork.jpg=>out.png JPEG 2952x2124=>2000x2000 2000x2000+0+0 8-bit sRGB 572KB 0.000u 0:00.000
convert: pixels are not authentic `artwork.jpg' # error/cache.c/QueueAuthenticPixelCacheNexus/4017.
It's hard to debug without the files and without knowing what you are trying to achieve, but I'll say what I see and maybe that will help. Here is what I think you have in the various layers:
0 - artwork 1800px wide
1 - artwork extended to 2000x2000
2 - clone of (1)
3 - clone of (2)
and then we come to the last line... and you delete 0--2 which is suspicious, did you mean 0-2, because 0--2 is actually 0,1.
So what did you mean to have in your image list after this -delete 0--2, I mean, how many images? I guess you meant to have 1 left.
Then you clone it, why do you do that? You could just copy the opacity right onto it and then you wouldn't need a -delete at the end?
No one can answer why this may have been happening but most could agree there is a better way of doing it, a few of these produce no error. It seems to be related to using clone request after a certain point in the chain.
Here are two commands that resolve this issue and provide the correct output image:
convert artwork.jpg +repage -thumbnail 1800x -gravity center -background white -extent 2000x2000 \
-gravity northwest displaceY.png +repage -compose over -compose displace -define compose:args=0x5% -composite \
-gravity northwest displaceX.png +repage -compose over -compose displace -define compose:args=5x0% -composite \
-gravity center alpha.png -compose over -compose copy_opacity -composite final.png
or
convert artwork.jpg +repage -thumbnail 1800x -gravity center -background white -extent 2000x2000 \
-gravity northwest displaceX.png displaceY.png +repage -compose over -compose displace -define compose:args=0x5% -composite \
-gravity center alpha.png -compose over -compose copy_opacity -composite final.png
Thanks to Fred over in the ImageMagick forums.
How to modify this code so mogrify will generate thumbnails only for the first frame of animated gifs?:
mogrify -resize 80x80 -background white -gravity center -extent 80x80 -format jpg -quality 75 -path thumbnails *.gif
The select frame notation would be [N] immediately after the filename; where N is the frame number you wish to select. See Selecting Frames section under the input filename examples.
mogrify -resize 80x80 \
-background white \
-gravity center \
-extent 80x80 \
-format jpg \
-quality 75 \
-path thumbnails \
*.gif[0]
I have a case where I need to combine two transparent layers on top of JPEG files.
Here a sample setup:
wget -O bg.jpg http://www.grahamowengallery.com/photography/Flowers/roadside-flowers.jpg
wget -O layer.png http://www2.picturepush.com/photo/a/6271450/640/TRANSPARENT-EMBELLISHMENTS/pink-flower-transparent-png.png
wget -O logo.png http://upload.wikimedia.org/wikipedia/commons/0/0d/Imagemagick-logo.png
I can get desired result with commands:
composite bg.jpg \( -compose Overlay layer.png \) bg2.jpg
composite bg2.jpg \( -compose Overlay logo.png \) result.jpg
This is good, but I want to avoid writing bg2.png to drive.
I tried:
composite bg.jpg \( -compose Overlay layer.png \) \( -compose Overlay logo.png \) result2.jpg
but this results on layer.png on black background. How can I fix this?
I couldn't make composite working, but convert works:
convert.exe bg.jpg layer.png -compose Overlay -composite logo.png -compose Overlay -composite result2.jpg
Further reading: http://www.imagemagick.org/Usage/compose/
I can not test this at the moment but you may be able to use layers merge and you should be able to use the URLs in your code.
$cmd = "http://www.grahamowengallery.com/photography/Flowers/roadside-flowers.jpg ".
" http://www2.picturepush.com/photo/a/6271450/640/TRANSPARENT-EMBELLISHMENTS/pink-flower-transparent-png.png ".
" http://upload.wikimedia.org/wikipedia/commons/0/0d/Imagemagick-logo.png -layers merge ";
exec(" convert $cmd result.jpg ");
You are not using any positioning for your layers - are you going to introduce that later? If so you can add -page +0+0 in front of each image to locate them where you want. +0+0 would be changed to the location.