I would like to be able to take 5 JPG images and process them with ImageMagick to create an effect showing the photos as a stack of Polaroid-like prints.
Assuming all photos are the same aspect ratio, they need to be resized to the same size, a 10px Polaroid-like border applied, then all slightly rotated and offset such that images below the top one are partially visible around the edges.
The rotation/offset doesn't need to be random as such - it could be hand-coded for each image in the stack if it is easier than doing it truly random?
Here is an example of the effect I am aiming for:
Can someone help with the correct parameters to use - I'm assuming we would want to use convert?
Edit: I already knew about the example contained on the ImageMagick page, but it doesn't specifically address my requirements - they clone the original image, they don't use multiple separate images. They also don't do a great job of explaining in each example exactly what every option does - they assume you already have spent hours (or days!) experimenting with the millions of options available. A bit difficult for someone who has never used the tool to master without a lot of work.
convert thumbnail.gif \
-bordercolor white -border 6 \
-bordercolor grey60 -border 1 \
-bordercolor none -background none \
\( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \
\( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \
\( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \
\( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \
-delete 0 -border 100x80 -gravity center \
-crop 200x160+0+0 +repage -flatten -trim +repage \
-background black \( +clone -shadow 60x4+4+4 \) +swap \
-background none -flatten \
poloroid_stack.png
... it would be great if someone could expand on this example and show me how to modify it to achieve my desired results as above.
Here is the command I found to give a pretty good result for what I needed - thanks to #Jim Lindstrom for putting me on the right track.
convert \
img-5.jpg -thumbnail 300x200 -bordercolor white -border 10 \
-bordercolor grey60 -border 1 -bordercolor none \
-background none -rotate -4 \
\
\( img-2.jpg -thumbnail 300x200 -bordercolor white -border 10 \
-bordercolor grey60 -border 1 -bordercolor none \
-background none -rotate 6 \
\) \
\
\( img-3.jpg -thumbnail 300x200 -bordercolor white -border 10 \
-bordercolor grey60 -border 1 -bordercolor none \
-background none -rotate -2 \
\) \
\
\( img-1.jpg -thumbnail 300x200 -bordercolor white -border 10 \
-bordercolor grey60 -border 1 -bordercolor none \
-background none -rotate -4 \
\) \
\
\( img-4.jpg -thumbnail 300x200 -bordercolor white -border 10 \
-bordercolor grey60 -border 1 -bordercolor none \
-background none -rotate 4 \
\) \
\
-border 100x80 -gravity center +repage -flatten -trim +repage \
-background black \( +clone -shadow 60x4+4+4 \) +swap -background none \
-flatten stack.png
Here is the output I get from my images using the above command:
It's not perfect yet, I have some more tweaks I'd like to do which I'll ask about in a separate question.
The docs for "convert" show almost exactly how. Search for "nice looking pile of photos" on http://www.imagemagick.org/Usage/thumbnails/#polaroid
Here's another way of doing it that makes, hopefully, clearer how one would sub in their own photos:
# create four images we want to use as our polaroid stack (I'm using the same one for all
# one, but you don't have to)
curl -O http://www.imagemagick.org/Usage/thumbnails/thumbnail.gif
cp thumbnail.gif thumbnail1.gif
cp thumbnail.gif thumbnail2.gif
cp thumbnail.gif thumbnail3.gif
cp thumbnail.gif thumbnail4.gif
rm thumbnail.gif
# You can easily see the recurring portion of this command. You could build
# it up programmatically and then execute it, for however many images you want.
# I've also simplified the example in their docs by hard-coding some rotation
# angles. Feel free to get fancy, or just hard code an array of them and keep
# grabbing the next one.
convert \
thumbnail1.gif \
-bordercolor white -border 6 \
-bordercolor grey60 -border 1 \
-bordercolor none -background none \
-rotate 20 \
-trim +repage \
\
\( \
thumbnail2.gif \
-bordercolor white -border 6 \
-bordercolor grey60 -border 1 \
-bordercolor none -background none \
-rotate -8 \
-trim +repage \
\) \
-gravity center \
-composite \
\
\( \
thumbnail3.gif \
-bordercolor white -border 6 \
-bordercolor grey60 -border 1 \
-bordercolor none -background none \
-rotate 3 \
-trim +repage \
\) \
-gravity center \
-composite \
\
\( \
thumbnail4.gif \
-bordercolor white -border 6 \
-bordercolor grey60 -border 1 \
-bordercolor none -background none \
-rotate -17 \
-trim +repage \
\) \
-gravity center \
-composite \
\
-crop 200x160+0+0 +repage -flatten -trim +repage \
-background black \( +clone -shadow 60x4+4+4 \) +swap \
-background none -flatten \
\
poloroid_stack.png
I use Simpon Hampel Code with some change in this :
How Margin Image with shadow in imagemagick?
please check it..
Related
I have a batch of images that need a transparent background. I am able to create a black/white mask of the lighter and darker regions and want to use this mask to keep the pixels, which are white in the mask unchanged and set all pixel to transparent, which are black. The best outcome so far I got with
convert $FILE -rotate "-90<" $ROTATED
convert $ROTATED \
+dither \
-colors 2 \
-fill black \
-draw 'color 0,0 floodfill' \
-flop \
-draw 'color 0,0 floodfill' \
-flop \
-white-threshold 0 \
$MASK
convert $ROTATED -mask $MASK -compose copy-opacity -composite $OUT
But the last command just "ghosts" the whole image. How can I "cut out" the black pixels and keep the white pixels unchanged?
This is what I get so far.
You simply need to remove the "-mask" from your command line leaving your mask image (and add -alpha off). So the following works fine for me in ImageMagick 6.
Input:
convert star.png \
+dither \
-colors 2 \
-fill black \
-draw 'color 0,0 floodfill' \
-flop \
-draw 'color 0,0 floodfill' \
-flop \
-white-threshold 0 \
mask.png
convert star.png mask.png -alpha off -compose copy-opacity -composite out.png
Mask:
Result:
Download the result to see that the background is fully transparent.
If using Imagemagick 7, then change convert to magick
ADDITION
Here is one way to do that with MPR. Note the +swap.
convert star.png \
-write mpr:star \
+dither \
-colors 2 \
-fill black \
-draw 'color 0,0 floodfill' \
-flop \
-draw 'color 0,0 floodfill' \
-flop \
-white-threshold 0 \
mpr:star \
+swap \
-alpha off \
-compose copy-opacity -composite \
out.png
You can also do it with a clone and parentheses.
convert star.png \
\( +clone \
+dither \
-colors 2 \
-fill black \
-draw 'color 0,0 floodfill' \
-flop \
-draw 'color 0,0 floodfill' \
-flop \
-white-threshold 0 \) \
-alpha off \
-compose copy-opacity -composite \
out.png
I get the same result as above.
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.
Can anyone please help me to generate command for following image?
https://drive.google.com/file/d/0B2vZnIXu1nOweDI1aEJRYTYtSWM/view?pli=1
The command which i tried is as follows.
convert -size 5256.00x2799.00 xc:transparent -gravity Center -font MyriadProRegular.otf ^
-pointsize "83.00" -interword-spacing 30 -stroke none ( ( -size 1x29 xc:"#A89AD7-#9E87BD" ) ( -size 1x30 gradient:"#A581B1-#B16D92" ) ( -size 1x30 gradient:"#C57195-#D47396" ) -append -scale 89x89! -write mpr:grad ) -fill mpr:grad ^
-annotate +1238.00-1092.00 "[Child 5], &" ^ -delete 1 ^
final_result.png
Exact issue i am facing is to get gradient effect in font.
Not too sure what your exact difficulty is, but maybe this wil help you get there in simple steps, each of which can be debugged and improved individually...
First generate your text:
convert -font MyriadPro -pointsize 83 -background none label:"[Child 5], &" text.png
Now generate your blurred gradient:
convert -size 376x29 \
gradient:"#A89AD7-#9E87BD" \
gradient:"#A581B1-#B16D92" \
gradient:"#C57195-#D47396" \
-append -blur 0x10 gradient.png
Now overlay:
convert gradient.png text.png -compose copy-opacity -composite result.png
The blended curve your attempting is closer to interpolation than a stacked series of gradients.
Try using -spare-color, examples here, and experiment with blending each color-stop.
convert -size 100x100 xc: -sparse-color Inverse \
'0,0 #A89AD7 0,15 #9E87BD 0,33 #A581B1 0,66 #B16D92 0,85 #C57195 0,99 #D47396' \
preview.png
convert -size 400x100 xc: \( \
-size 1x100 xc: -sparse-color Inverse \
'0,0 #A89AD7 0,15 #9E87BD 0,33 #A581B1 0,66 #B16D92 0,85 #C57195 0,99 #D47396' \
-write mpr:grad +delete
\) \
-pointsize 63 -interword-spacing 30 \
-stroke none -fill mpr:grad \
-gravity Center -annotate 0 "[Child 5], &" \
final_result.png
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