Page 1 of 1
Cut image into pieces and recombine 3 horizontal
Posted: 2016-01-07T03:10:21-07:00
by Zoker
Hi there,
I have three questions:
- I want to first cut a image vertical into multiple pieces of the same size. So I have a 800x5000px image for example and want to have 800x1200px images (the last image should be only the rest 800x200px image + white background)
Code: Select all
convert -crop 800x1200 input.png output_%d.png
But I want to start the first cut at the bottom of the image, not at the top. How can I do this?
- After that I want to take these pieces and put 3 of them into a horizontal row.
This is my code:
Code: Select all
convert -append cropped_*.png out.png
How can I set, that it only takes 3 images and after these 3, create a new image with the next 3 images?
- Is there also a way to combine these two scripts? Like first cut 3 pieces (starting at the bottom), then combine them vertically, then cut an other 3 and combine them etc.
Thank you very much!
Zoker
Re: Cut image into pieces and recombine 3 horizontal
Posted: 2016-01-07T06:07:44-07:00
by sas
Zoker wrote:But I want to start the first cut at the bottom of the image, not at the top. How can I do this?
Adding "-flip" before and after the "-crop" operation seems to work:
Code: Select all
convert -flip -crop 800x1200 -flip input.png output_%d.png
Zoker wrote:How can I set, that it only takes 3 images and after these 3, create a new image with the next 3 images?
You could use "montage":
Code: Select all
montage cropped_*.png -geometry +0+0 -tile 3x1 out_%d.png
Zoker wrote:Is there also a way to combine these two scripts?
This seems to work:
Code: Select all
montage input.png -flip -crop 800x1200 -flip \
-geometry +0+0 -tile 3x1 out_%d.png
Re: Cut image into pieces and recombine 3 horizontal
Posted: 2016-01-07T14:38:52-07:00
by Zoker
sas wrote:
Code: Select all
convert -flip -crop 800x1200 -flip input.png output_%d.png
Awesome, thank you!
But he does not flip the images back again. Only the last one (in this case the top part) is flipped back, but no all others.
The others are not only flipped vertically, but also horizontal...
Re: Cut image into pieces and recombine 3 horizontal
Posted: 2016-01-07T15:31:01-07:00
by fmw42
This should flip all image back again and number them from the original bottom. The last section at the top of the image may be a partial size. The input image needs to come before the crop:
Code: Select all
convert input.png -flip -crop 800x1200 -flip output_%d.png
Re: Cut image into pieces and recombine 3 horizontal
Posted: 2016-01-07T16:09:37-07:00
by Zoker
fmw42 wrote:This should flip all image back again and number them from the original bottom. The last section at the top of the image may be a partial size. The input image needs to come before the crop:
Code: Select all
convert input.png -flip -crop 800x1200 -flip output_%d.png
Perfect thanks! Can I somehow set the starting number for the %d?
So it does not start with 1, but with 134 e.g
Re: Cut image into pieces and recombine 3 horizontal
Posted: 2016-01-07T16:48:26-07:00
by fmw42
It should have started with 0, not 1. I believe this should work to start at 134.
Code: Select all
convert input.png -flip -crop 800x1200 -flip -scene 134 output_%d.png
Re: Cut image into pieces and recombine 3 horizontal
Posted: 2016-01-07T17:44:09-07:00
by Zoker
fmw42 wrote:It should have started with 0, not 1. I believe this should work to start at 134.
Code: Select all
convert input.png -flip -crop 800x1200 -flip -scene 134 output_%d.png
Thank you so much!
Now everything works well, but one thing:
Code: Select all
montage cropped_*.png -geometry +0+0 -tile 3x1 out_%d.png
Most images are put together correctly, but some of them are not in the right order:
Montage 1:
out_1
out_2
out_3
...
Montage x:
out_128
out_129
out_13
So it seems, that he takes the out_13 straight after the out_129.
How can I fix this?
Re: Cut image into pieces and recombine 3 horizontal
Posted: 2016-01-07T17:53:10-07:00
by fmw42
If you have many pieces than you need to use leading zeros in your file names. If you have numbers from 0 to 999, then use %03d. If you have numbers from 0 to 9999, then use %04d. But I am not sure why you should be getting 1,2,3,...13... when you start the numbering from 134?
Code: Select all
convert input.png -flip -crop 800x1200 -flip -scene 134 output_%03d.png
That should number them from 134 - XXX, but you really do not need the %03d vs %d, since your numbers should be in the range 134 to XXX (unless you have more than 999 pieces and then you would need %04d at least)
Re: Cut image into pieces and recombine 3 horizontal
Posted: 2016-01-07T18:01:17-07:00
by Zoker
Works!!!
I have two images and the first is from 1-133 and the second from 134-x