I want to convert command below to Magick.Net Code.
convert sunset_lake.png \
\( -background none -pointsize 24 -fill white label:"TESTING" -rotate 20 -write mpr:tile +delete \) \
\( +clone -tile mpr:tile -draw "color 0,0 reset" \) \
-compose over -composite sunset_lake_tile_text.png
I am not sure what is the corresponding code for -write mpr:tile +delete and mpr:tile -draw "color 0,0 reset".
Any help would be appreciated.
Related
Hello I want to add a same image to the left side of multiple images. First image is a legend and it common for all the 6 images which I later want to montage 3x2.
I tried this command below before montaging and it did not work. I wanted to see if I could make it work without adding a for loop, which slows down the code.
convert +append image_3_1.png image_1_[1-6].png -geometry +10+0 test.png
I want the image_3_1 added to all the 6 images starting with image_1. Any ideas?
Your question is unclear about:
what your input and expected output images look like or how big they are,
whether you actually need the intermediate images or just the montage,
what the actual issue is with for loops
So here are some ideas...
Option 1
This one avoids for loops and multiple invocations of magick by using a single magick and loading the side image just once and cloning it in memory:
magick side.png \
\( +clone image_1.png +append -write out_1.png +delete \) \
\( +clone image_2.png +append -write out_2.png +delete \) \
\( +clone image_3.png +append -write out_3.png +delete \) \
\( +clone image_4.png +append -write out_4.png +delete \) \
\( +clone image_5.png +append -write out_5.png +delete \) \
image_6.png +append out_6.png
It produces 6 output files as follows:
Option 2
This one avoids for loops by running 6 copies of magick in parallel:
magick side.png image_1.png +append out_1.png &
magick side.png image_2.png +append out_2.png &
magick side.png image_3.png +append out_3.png &
magick side.png image_4.png +append out_4.png &
magick side.png image_5.png +append out_5.png &
magick side.png image_6.png +append out_6.png &
wait
It produces the same 6 output files as above.
Option 3
This does the same by using GNU Parallel to do it more succinctly:
parallel magick side.png image_{}.png +append out_{}.png ::: {1..6}
Option 4
If you don't need the intermediate files, and just want the montage:
parallel -k magick side.png {} +append ppm:- ::: image_*png | magick montage -tile 2x3 -geometry +5+5 ppm:- montage.png
Option 5
This is much the same, avoiding producing the intermediate output files, and also avoiding using GNU Parallel:
magick side.png \
\( +clone image_1.png +append -write ppm:- +delete \) \
\( +clone image_2.png +append -write ppm:- +delete \) \
\( +clone image_3.png +append -write ppm:- +delete \) \
\( +clone image_4.png +append -write ppm:- +delete \) \
\( +clone image_5.png +append -write ppm:- +delete \) \
image_6.png +append ppm:- | magick montage -background black -geometry +5+10 -tile 2x3 ppm:- montage.png
Option 6
This one uses no for loops, a single process, no separate montage command and generates no intermediate files:
magick side.png -write MPR:side +delete \
\( MPR:side image_1.png MPR:side image_2.png +append \) \
\( MPR:side image_3.png MPR:side image_4.png +append \) \
\( MPR:side image_5.png MPR:side image_6.png +append \) \
-append montage.png
Replace the +append and -append with -smush for more layout and inter-image spacing flexibility.
Option 7
Maybe something like this with -smush:
magick side.png -write MPR:side +delete -background cyan \
\( MPR:side image_1.png MPR:side image_2.png +smush 10 \) \
\( MPR:side image_3.png MPR:side image_4.png +smush 10 \) \
\( MPR:side image_5.png MPR:side image_6.png +smush 10 \) \
-smush 30 montage.png
My guess is that option 6 would be the fastest on most machines in most circumstances, if it is flexible enough for you. If you need more flexibility, go with option 7 or 5.
Keywords: ImageMagick, image processing, montage, layout, parallel, smush.
I want to create image watermark like Shutterstock. I have tried but not able to replicate it. I tried with the following command. The issue is for me is i not able to add diagonal random text to image as Shutterstock does. I have tried many options with no luck.
infile="zoom.jpg"
ww=$(convert -ping "$infile" -format "%[fx:w-1]" info:)
hh=$(convert -ping "$infile" -format "%[fx:h-1]" info:)
convert "$infile" \
-fill "graya(100%,0.75)" \
-draw "line 0,0 $ww,$hh line $ww,0 0,$hh" -alpha off \
-fill "graya(50%,0.25)" \
tile_aqua_500_text_x_text.jpg
composite -dissolve 35 -gravity center logo.png tile_aqua_500_text_x_text.jpg tile_aqua_500_text_x_text.jpg
convert -background none -size 220x320 xc:none -font DejaVu-Sans-Bold -pointsize 30 \
-gravity North -draw "rotate -22 fill grey text 20,10 'knot9'" \
-gravity West -draw "rotate -27 fill grey text 5,15 '89898989'" \
miff:- |\
composite -dissolve 70 -tile - tile_aqua_500_text_x_text.jpg tile_aqua_500_text_x_text.jpg
width=`identify -format %w tile_aqua_500_text_x_text.jpg`; \
convert -background '#0008' -fill white -gravity center -size ${width}x30 -pointsize 10 -font DejaVu-Sans-Bold\
caption:"\nThis image is Copyrighted by Knot9 \n www.knot9.com | Image Id: 89898989\n" \
tile_aqua_500_text_x_text.jpg +swap -gravity south -composite tile_aqua_500_text_x_text.jpg
My Output is
Requirement is
In ImageMagick, you can do the following. Create a small text image on a transparent background using label:. Rotate it. Pad it to control the spacing. Tile it out to fill the image. Then composite the tiled out image over your background image.
Image:
convert lena.png \
\( -size 100x -background none -fill white -gravity center \
label:"watermark" -trim -rotate -30 \
-bordercolor none -border 10 \
-write mpr:wm +delete \
+clone -fill mpr:wm -draw 'color 0,0 reset' \) \
-compose over -composite \
lena_watermark.png
If using ImageMagick 7, then change convert to magick
See https://imagemagick.org/Usage/canvas/#tile_memory for tiling
With these 3 separates codes I create the following 3 images with desired size for each one. I'm failing in merging in a single command.
This code produces P1.png
convert \( \( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 1" \) \
\( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 2" \) \
+smush +2 -write P1.png \) null:
P1.png (854x37)
This code produces P2.png
convert \( \( -size 881x488 xc:"#FFE97F" \) \
\( -size 881x488 xc:"#00FF90" \) \
+smush +6 -resize 1180x441! -write P2.png \) null:
P2.png (1180x441)
This code produces P3.png
convert \( \( -size 1104x89! xc:"#00137F" -fill white -font Calibri-Bold -pointsize 48 -gravity center -annotate +0+0 "Different boxes" \) \
-write P3.png \) null:
P3.png (1104x89)
If I join the 3 images in an image editor visually (like Paint.net) the resulting image is of 1180x606 and the resolution is 96 pixels per inch.
How can I join these 3 commands in a single "convert" command in order the final image be of 1180x606 in size?
I've tried with this code, but I don't know how to construct the command correctly
convert \
\( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 1" \) \
\( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 2" \) \
+smush +2 \
-write mpr:numbers \
\
\(
\( -size 881x488 xc:"#FFE97F" \) \
\( -size 881x488 xc:"#00FF90" \) \
-resize 1180x441! +smush +6 mpr:numbers +swap -gravity center -smush +15 +gravity \
-write mpr:boxes \
-delete 0 \
\
\( -size 1104x89! xc:"#00137F" -fill white -font Calibri-Bold -pointsize 48 -gravity center -annotate +0+0 "Different boxes" \) \
mpr:boxes +swap -gravity center -smush +24 +gravity +write POut.png \) null:
The desired output is like this:
Thanks for any help.
UPDATE
When I see it in an image editor (Paint.net in my case) I can see and change resolution withot change pixel dimentions. Only dimentions of inches change.
Result.png original with Resolution=120 pixel/inch and size 1180x606
Result.png changed to Resolution=96 pixel/inch and size still is 1180x606 but inches dimentions changed
UPDATE 2
fmw42's code works fine creating from scratch 3 images and then merging them. My problem is if I use the same fmw42's script but instead to create
the yellow and green boxes I crop them from another image (source.png) the result.png is not the same. What is the issue when I add the cropped images?
I'm using this code:
convert \
source.png +repage -write mpr:img -delete 0--1 \
\( \
\( -size 1104x89! xc:"#00137F" -fill white -font Calibri-Bold -pointsize 48 -gravity center -annotate +0+0 "Different boxes" \) \
\) \
\
\( \
\( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 1" \) \
\( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 2" \) \
+smush +2 \
\) \
-smush +24 \
\
\( \
\( mpr:img -crop 881x488+71+376 \) \
\( mpr:img -crop 881x488+992+376 \) \
+smush +6 -resize 1180x441! \
\) \
-smush +15 \
resultX.png
This is source.png
And this is the output that is not correct
Does this do what you want? ImageMagick 6 command could be like the following as one way to do it:
convert \( \( -size 1104x89! xc:"#00137F" -fill white -font Calibri-Bold -pointsize 48 -gravity center -annotate +0+0 "Different boxes" \) \
-write P3.png \) \
\
\( \( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 1" \) \
\( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 2" \) \
+smush +2 -write P1.png \) \
-smush +24 \
\
\( \( -size 881x488 xc:"#FFE97F" \) \
\( -size 881x488 xc:"#00FF90" \) \
+smush +6 -resize 1180x441! -write P2.png \) \
-smush +15 \
result.png
Note that I may not have used the same font as you.
Please review:
https://imagemagick.org/Usage/basics/#parenthesis
https://imagemagick.org/Usage/layers/#smush
https://imagemagick.org/Usage/files/#write
To answer your Update2 question: You need to resent the gravity with +gravity after you have used it with -gravity center. Also you need to add +repage after your crops.
convert \
source.png +repage -write mpr:img -delete 0--1 \
\( \
\( -size 1104x89! xc:"#00137F" -fill white -font Calibri-Bold -pointsize 48 -gravity center -annotate +0+0 "Different boxes" \) \
\) \
\
\( \
\( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 1" \) \
\( -size 426x37 xc:"#4FA7FF" -fill black -font Calibri-Bold -pointsize 32 -gravity center -annotate +0+0 "Number 2" \) \
+smush +2 \
\) \
-smush +24 +gravity \
\
\( \
\( mpr:img -crop 881x488+71+376 +repage \) \
\( mpr:img -crop 881x488+992+376 +repage \) \
+smush +6 -resize 1180x441! \
\) \
-gravity center -smush +15 \
resultX.png
With well considered use of ImageMagick's memory registers, like "mpr:something", you can simplify the construction of your entire image to something like this...
convert -gravity center -background white -font helvetica \
-size 1104x89 xc:"#00137F" -fill white -pointsize 48 \
-annotate +0+0 "Different boxes" -write mpr:diffbox +delete \
-size 426x37 xc:"#4FA7FF" xc:"#4FA7FF" -fill black -pointsize 32 \
-annotate +0+0 "Number %[fx:t+1]" +smush 2 -write mpr:numbox +delete \
-size 588x441 xc:"#FFE97F" xc:"#00FF90" +smush 4 \
mpr:numbox +insert -smush 15 mpr:diffbox +insert -smush 24 result.png
That works for me on Windows Ubuntu bash shell running ImageMagick 6.8.9-9. You'll have to specify your own font, and if you're using the same font for everything you only have to specify it once.
A possible history for this question: Eliminate slow speed factor in ffmpeg and image-magic commands
I am creating a GIF using this command with wiper effect,
convert -gravity southeast logo.png -write MPR:logo \
\( before.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:before \) \
\( after.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:after \) \
-delete 0--1 \
MPR:before \( MPR:after -set delay 25 -crop 15x0 -reverse \) \
MPR:after \( MPR:before -set delay 27 -crop 15x0 \) \
-set delay 2 -loop 0 temp.gif -delete 1--1 -resize 640x thumb.jpg
Which is working all fine, but it creates a gif of size 3MB+, as there are more than 100 frames in wiper effect.
How can we decrease the number of frames for the wiper effect as well as the quality remains the same, but size decreases? I tried to attach different parameters with different loop values but nothing worked.
Here are 3 Imageamagick commands. The first is yours above. In the second I create a common color map image from the two input images (before and after) and apply that to each frame. In the third, I do the same color map processing, but reduce the number of frames. I took all the images from the web site and animation referenced and put the new logo in the bottom left corner, since there was already one in the bottom right corner. Note that I added -layers optimize to all, which decreased the file size considerably.
logo:
before:
after:
Method 1 (original):
convert -gravity southwest everlogo.png -write MPR:logo \
\( before.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:before \) \
\( after.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:after \) \
-delete 0--1 \
MPR:before \( MPR:after -set delay 25 -crop 15x0 -reverse \) \
MPR:after \( MPR:before -set delay 27 -crop 15x0 \) \
-set delay 2 -layers optimize -loop 0 temp1a.gif
2,246,665 bytes
174 frames
Result is too large to upload here.
Method2 (common color map):
convert -gravity southwest \
everlogo.png -write MPR:logo +delete \
\( before.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:before \) \
\( after.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:after \) \
-delete 0--1 \
\( MPR:before MPR:after +append +dither -colors 255 -unique-colors -write MPR:colors +delete \) \
MPR:before +dither -remap MPR:colors \( MPR:after +dither -remap MPR:colors -set delay 25 -crop 15x0 -reverse \) \
MPR:after+dither -remap MPR:colors \( MPR:before +dither -remap MPR:colors -set delay 27 -crop 15x0 \) \
-set delay 2 -layers optimize -loop 0 temp1b.gif
2,004,345 bytes
173 frames
Method 3 (common color map; twice the crop width and four times the delay; adjust the delay as desired to match better Method 2)
convert -gravity southwest \
everlogo.png -write MPR:logo +delete \
\( before.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:before \) \
\( after.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:after \) \
-delete 0--1 \
\( MPR:before MPR:after +append +dither -colors 255 -unique-colors -write MPR:colors +delete \) \
MPR:before +dither -remap MPR:colors \( MPR:after +dither -remap MPR:colors -set delay 100 -crop 30x0 -reverse \) \
MPR:after+dither -remap MPR:colors \( MPR:before +dither -remap MPR:colors -set delay 108 -crop 30x0 \) \
-set delay 4 -layers optimize -loop 0 temp1c.gif
1,927,359 bytes
87 frames
I am bit surprised that reducing the number of frames so significantly does not make a commensurate decrease in animation file size. But I suspect that is due to the -layers optimize.
ADDITION:
Also in all the code above, I do not understand the use of setting the delay of 25 and 27 inside the parentheses and then setting it again to 2 afterwards. I do not think animated gifs can have different delays. The only one that matters is the final one.
So just in terms of delays and number of frames, these two do the same. The first uses -crop 15x0 and -set delay 4 and the second use -crop 30x0 and -set delay 8. This produces the same speed animation, but the second has fewer frames. The first is 174 and the second is 88 and so more coarse steps. But the file sizes are about the same. So it seems that the common color map causes the largest decrease in file size.
convert -gravity southwest everlogo.png -write MPR:logo \
\( before.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:before \) \
\( after.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:after \) \
-delete 0--1 \
MPR:before \( MPR:after -crop 15x0 -reverse \) \
MPR:after \( MPR:before -crop 15x0 \) \
-set delay 4 -layers optimize -loop 0 temp3.gif
frames 174
2,246,665 bytes
convert -gravity southwest everlogo.png -write MPR:logo \
\( before.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:before \) \
\( after.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:after \) \
-delete 0--1 \
MPR:before \( MPR:after -crop 30x0 -reverse \) \
MPR:after \( MPR:before -crop 30x0 \) \
-set delay 8 -layers optimize -loop 0 temp2.gif
frames 88
2,174,954 bytes
I want resize, crop and concatenate really many images.
I don't want to write the intermediate results to disk, just the final result only.
My script is :
montage -mode concatenate \
\( test.jpg -thumbnail "150x100>" -background white -gravity center -extent 150x100 -page 150x100+0+0 \) \
\( -clone 0 -crop 23x16+80+0 -background white -extent 23x16 \) \
\( -clone 0 -crop 23x16+16+87 -background white -extent 23x16 \) \
...
-delete 0 -quality 100% thumb.jpg
I got always the following error:
montage.im6: geometry does not contain image `test.jpg' # warning/transform.c/CropImage/574.
I tried to use the "repage" and "page" parameters, but I was unsuccessful with them.
Any idea?
Update
Mark asked for examples. So I try to write down the different steps which I would like to merge in one single step:
convert logo: test.jpg
convert test.jpg -thumbnail "150x100>" -background white -gravity center -extent 150x100 -page 150x100+0+0 test.resized.jpg
montage -mode concatenate test.resized.jpg \
\( -clone 0 -crop 23x16+80+20 -background white -extent 23x16 \) \
\( -clone 0 -crop 23x16+92+74 -background white -extent 23x16 \) \
\( -clone 0 -crop 23x16+100+80 -background white -extent 23x16 \) \
-delete 0 -quality 100% result.thumb.jpg
And the results:
you can see here the expected result.
http://phspring.nl/stackoverflow28101334.jpg
I must admit this one has me mystified! I cannot get it to work how you tried, or how I would want to do it at all. I found that I can only make it work if I add a +repage but if I do that it forgets the -extent, so I keep ending up with 2 commands. I also find that +clone refuses to work in place of -clone 0 for this example, which also mystifies me.
The only way I can make it work, and avoid the intermediate file is to stream the output of the first convert to the second one.
convert logo: -resize "150x100>" -background white -gravity center -extent 150x100 JPG:- | \
convert JPG:- \
\( -clone 0 -crop 23x16+80+20 \) \
\( -clone 0 -crop 23x16+92+74 \) \
\( -clone 0 -crop 23x16+100+80 \) \
-delete 0 +append out.jpg