Page 1 of 1

crop page in multipage tif

Posted: 2012-02-15T13:23:04-07:00
by gmccartney
I am trying to crop a single page of a multipage tif in a single operation.

Source.tif is a 15 page tif file. I want to crop page 2 to 1700 X 1300 @ 250,50.

I can get it to work using 3 separate commmands;
convert Source.tif[1] -crop 1700X1300+250+50 +repage croppedPage.tif
convert Source.tif -delete 1 deletedPage.tif
convert deletedPage.tif croppedPage.tif -insert 1 newSource.tif

Although this works, it is slow on large multipage files. So, I want to do it in one command.
I tried:
convert Source.tif ( -delete 1 ) Source.tif[1] -crop 1700X1300+250+50 +repage -insert 1 newSource.tif
and:
convert Source.tif ( -delete 1 ) Source.tif[1] ( -crop 1700X1300+250+50 +repage ) -insert 1 newSource.tif
but that crops every page.

I tried:
convert Source.tif ( -delete 1 ) ( Source.tif[1] -crop 1700X1300+250+50 +repage ) -insert 1 newSource.tif
but that just moves the last page to the first.

Any ideas?

Gerald

Re: crop page in multipage tif

Posted: 2012-02-15T13:31:19-07:00
by gmccartney
I got it to work using:
convert Source.tif ( Source.tif[1] -crop 1700X1300+250+50 +repage ) -insert 1 ( -delete 2 ) newSource.tif
note: incremented the delete page number since I inserted in front of it...

No idea why reversing the order of operations worked, but it did...

Gerald

Re: crop page in multipage tif

Posted: 2012-02-15T13:38:35-07:00
by fmw42
I don't believe that you need the parens around the -delete 2

You don't have to read the file twice. All the frames of the input image are counted separately.

So this should work to copy only frame 1 to be cropped.

convert Source.tif ( -clone 1 -crop 1700X1300+250+50 +repage ) -insert 1 -delete 2 newSource.tif

Re: crop page in multipage tif

Posted: 2012-02-15T16:08:10-07:00
by gmccartney
The -clone operator worked perfectly.
Thank you.

Re: crop page in multipage tif

Posted: 2012-02-15T23:14:12-07:00
by anthony
The better (nicer) way is this...
convert Source.tif ( -clone 1 -crop 1700X1300+250+50 +repage ) -swap 1 +delete newSource.tif

More about this in IM Exmaples, Basics, Combining Image Sequence Operations
http://www.imagemagick.org/Usage/basics/#seq_combine