Page 1 of 1

Split image to 2 files with different width

Posted: 2018-03-04T08:00:51-07:00
by Gurthfin
Hi,
I think I do this wrong way, but I wanna split image with 2000px width 1000px height to 2 files, where first have 900px width and second 1200px width. I find this

Code: Select all

magick convert t_ari13a.png -crop 900x1000 tile-%d.png
but this produce 3 files 900x1000, 900x1000 and 200x1000. I looking at crop example and trying everything, but nothing works.

Oh yes, I forgot. I known only vertical split is at 900px.

Re: Split image to 2 files with different width

Posted: 2018-03-04T08:46:36-07:00
by Bonzo
The problem is your code gets as many images as it can out of the available width with your width setting; hence the 200 wide piece. I am not sure of a way around it other than doing two crops. There may be something here but I could not see anything: https://www.imagemagick.org/Usage/crop/

With V7 you should only need magick and not magick convert.

Re: Split image to 2 files with different width

Posted: 2018-03-04T09:02:53-07:00
by snibgo
If you want two different crops, I would do it like this (Windows BAT syntax):

Code: Select all

magick t_aril3a.png ^
  ( -clone 0 -crop 900x1000+0+0 +repage ) ^
  ( -clone 0 -crop 1200x1000+0+0 +repage ) ^
  tile-%d.png

Re: Split image to 2 files with different width

Posted: 2018-03-04T09:21:20-07:00
by Gurthfin
It wont works. I have lot of pictures and I known only split width. Next picture is 1055x744 and split is on 517.

Re: Split image to 2 files with different width

Posted: 2018-03-04T09:22:52-07:00
by GeeMack
Gurthfin wrote: 2018-03-04T08:00:51-07:00I think I do this wrong way, but I wanna split image with 2000px width 1000px height to 2 files, where first have 900px width and second 1200px width. I find this

Code: Select all

magick convert t_ari13a.png -crop 900x1000 tile-%d.png
but this produce 3 files 900x1000, 900x1000 and 200x1000. I looking at crop example and trying everything, but nothing works.
If you want the first piece to be 900 pixels wide (or any particular width) and the second piece to contain the remainder of the image, there are several ways to accomplish this sort of thing. One simple method that comes to mind is something like this...

Code: Select all

magick input.png -crop 900x ( -clone 1--1 +append ) -delete 1--2 output-%d.png
That crops the image into as many 900 pixel wide pieces as it can, clones everything from the second piece onward and reassembles them, then deletes the unneeded parts before writing the two output images.

Re: Split image to 2 files with different width

Posted: 2018-03-04T09:34:48-07:00
by Gurthfin
Thank you, this works.
Is possible to use name of file and add a number to it -example

Code: Select all

magick t_ari13a.png -crop 900x ( -clone 1--1 +append ) -delete 1--2 [name]_%d.png
and produce
t_ari13a_d-0.png
t_ari13a_d-1.png

or something like that?

Re: Split image to 2 files with different width

Posted: 2018-03-04T09:35:27-07:00
by Bonzo
I thought you should be able to use -gravity but it didn't work.

Re: Split image to 2 files with different width

Posted: 2018-03-04T09:50:39-07:00
by GeeMack
Gurthfin wrote: 2018-03-04T09:34:48-07:00Is possible to use name of file and add a number to it -example

Code: Select all

magick t_ari13a.png -crop 900x ( -clone 1--1 +append ) -delete 1--2 [name]_%d.png
and produce
t_ari13a_d-0.png
t_ari13a_d-1.png
You can use the input file name to set the output file name like this...

Code: Select all

magick input.png -set filename: "%[t]" -crop 900x ( -clone 1--1 +append ) -delete 1--2 "%[filename:]-%d.png"

Re: Split image to 2 files with different width

Posted: 2018-03-04T10:09:38-07:00
by Gurthfin
Perfectly works, thank you very much