I know how to use -crop 50%x100% to split an image in half (50/50) but is there a way to crop into 40/60?
If I use
convert -crop 40%x100% in.jpg out.jpg
I end up getting:
out-0.jpg // 40%
out-1.jpg // 40%
out-2.jpg // remaining %
convert in.jpg -gravity west -crop 40%x100% +repage out1.jpg
convert in.jpg -gravity east -crop 60%x100% +repage out2.jpg
I'm sure there is a more complex way, but I would just do it in two commands.
You can do it in a single command like this:
convert in.jpg \
\( +clone -gravity east -crop 60x100% +repage +write east.jpg +delete \) \
-gravity west -crop 40x100% +repage west.jpg
Related
Hey all I have this code below that takes 2 images and merges them together with it fading in the center:
convert testingl.jpg -gravity West ^
testingr.jpg -gravity East ^
blend_mask.png -extent 1080x440 -gravity center -composite bothBlended.jpg
The above produces this:
Using this mask:
Taken from these 2 images (lowered res to fit on here):
testingl.jpg (original size 1224 x 1632)
testingr.jpg (original size 828 x 1792)
This code works great as-is. Does what I need it to do but with one exception - I am wanting to get more of each image into it. Like resize the image, crop from the center the image then take that and blend it. I need to keep the same 1080 x 440 overall size.
Do that with both would look something like this:
UPDATE 1
When running #fmw42's code:
convert ^
( testingl.jpg -resize 1080x440^ -gravity West -extent 1080x440 ) ^
( testingr.jpg -resize 1080x440^ -gravity East -extent 1080x440 ) ^
blend_mask.png -composite abc.jpg
I get this:
Your ImageMagick command does not generate your proposed output image. I think it is missing a resize and parentheses.
In Unix syntax, I need the following to get your output.
convert \
\( testingl.png -resize 1080x440^ -gravity West -extent 1080x440 \) \
\( testingr.png -resize 1080x440^ -gravity East -extent 1080x440 \) \
blend_mask.png -composite bothBlended1.jpg
or perhaps you want
convert \
\( testingl.png -resize 1080x440^ -gravity West -extent 1080x440 \) \
\( testingr.png -resize 1080x440! -gravity East -extent 1080x440 \) \
blend_mask.png -composite bothBlended2.jpg
I have the following image:
I would like to use ImageMagick to split it horizontally into two unequal parts of 40-60% (L-R). How do I do this?
You can do that as follows in ImageMagick 6. Read the image into MPR memory and delete the original. Then use the MPR copy to crop 40% once with gravity west and crop 60% again with gravity east (that is 40% from the left side and then 60% from the right side). Write those images and then exit with no output, i.e., null:
Unix Syntax:
convert red_rect.png +repage -write mpr:img +delete \
\( mpr:img -gravity west -crop 40x100%+0+0 +repage +write left.png \) \
\( mpr:img -gravity east -crop 60x100%+0+0 +repage +write right.png \) \
null:
For Windows,
convert red_rect.png +repage -write mpr:img +delete ^
( mpr:img -gravity west -crop 40x100%+0+0 +repage +write left.png ) ^
( mpr:img -gravity east -crop 60x100%+0+0 +repage +write right.png ) ^
null:
(In .bat file, double the % to %%)
(For ImageMagick 7, change convert to magick)
Left:
Right:
Just for fun, a slightly different version:
load image
make clone, crop left side and save, delete clone
revert to original, crop right side and save
magick GhLiu.png +repage \( +clone -crop 40x100%+0+0 +repage +write left.png +delete \) -gravity east -crop 60x100%+0+0 +repage right.png
I am trying to composite two images with gravity, and then position them within a larger image at a geometry.
When I try
magick -size 1045x837 xc:blue \( -size 345x437 xc:red \( -size 275x417 xc:white -resize 345x437 -gravity center \) -composite \) -geometry +26+53 -composite test-y.png
I get
and when I do
magick -size 1045x837 xc:blue \( -size 345x437 xc:red \( -size 275x417 xc:white -resize 345x437 \) -composite \) -geometry +26+53 -composite test-x.png
I get
I think this involves clone and related, maybe similar to this answer, but I just can't find the combo.
What do I need to do, to get the white centered within the red, and geometrically placed in the upper-left corner?
It's not clear exactly what you want, but I think you are falling foul of the fact that -gravity is a "setting". As such, it remains set until changed, so you probably want this, where I reset the gravity to NorthWest before the final composite:
magick -size 1045x837 xc:blue \( -size 345x437 xc:red \( -size 275x417 xc:white -resize 345x437 -gravity center \) -composite \) -gravity northwest -geometry +26+53 -composite result.png
You might find -extent a simpler way to fill out the white to a given size using a red background:
magick -size 1045x837 xc:blue \( -size 275x417 xc:white -resize 345x437 -background red -gravity center -extent 345x437 \) -gravity northwest -geometry +26+53 -composite result.png
I would like to crop image and flatten it over a second canvas.
for instance, my image1 crop would be=>
-crop 20x800+450+0
and I would like to put it at the position of my second image.
-page 0+0
this just doesn't work=>
convert -page 0+0 image1.jpg -crop 20x800+450+0 -layers flatten image2.jpg
how could I do this ?
thanks in advance
I find your question very hard to understand, but let's assume you have this:
# a canvas
convert -size 1200x1200 xc:gray canvas.png
and an image:
convert -size 1000x1000 gradient:red-blue image1.png
Then I am guessing you want this:
convert canvas.png \( image1.png -crop 20x800+450+0 \) -composite result.png
That works because the default -gravity is NorthWest, if you wanted it elsewhere you can do things like this:
convert canvas.png \( image1.png -crop 20x800+450+0 \) -gravity east -composite result.png
Or this, with an up-down offset from the South side:
convert canvas.png \( image1.png -crop 20x800+450+0 \) -gravity south -geometry +0+50 -composite result.png
Or with a left-right offset from the West side:
convert canvas.png \( image1.png -crop 20x800+450+0 \) -gravity west -geometry +100 -composite result.png
Or maybe you want to rotate the extracted crop before overlaying it:
convert canvas.png \( image1.png -crop 20x800+450+0 -rotate 90 \) -gravity north -geometry +0+20 -composite result.png
Or maybe you were trying to do it this way:
convert canvas.png -respect-parentheses \( -page +300+50 image1.png -crop 20x800+450+0 \) -layers flatten result.png
I can't figure out how to properly chain commands in ImageMagick
Things that do what I expect in isolation :
Resize and then crop
$ convert input.jpg -resize '400x400>' -gravity center -crop 300x400+0+0 +repage output.jpg
Apply overlay
$ convert -composite input.jpg overlay.png output.jpg
Annotate
$ convert input.jpg -annotate +55+357 'The text I want' output.jpg
I've had limited success in combining these together for instance :
$ convert \( input.jpg -resize '400x400>' -gravity center -crop 300x400+0+0 +repage \) mask.png -composite output.jpg
Resizes the image and crops it, then applies my overlay. However regardless of what I try I can't then get the annotation to appear.
What I want to do is something like :
$ convert \( input.jpg -resize '400x400>' -gravity center -crop 300x400+0+0 +repage \) mask.png -composite \( -annotate +55+357 'The text I want' \) output.jpg
Thanks.
Answering my own question :
Adding -gravity NorthWest before the annotation solves the problem.
$ convert input.jpg -resize '400x400>' -gravity center -crop 300x400+0+0 +repage mask.png -composite -gravity NorthWest -annotate +55+357 'The text I want' output.jpg
I believe this effectively resets the 0,0 after the crop / resize so the annotation appears where it is expected to.
Note that you don't need the parenthesis either.
Credit to snibgo on the ImageMagick forum.