crop page in multipage tif

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
gmccartney
Posts: 5
Joined: 2012-02-15T13:03:32-07:00
Authentication code: 8675308
Contact:

crop page in multipage tif

Post 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
Gerald McCartney
CGI Technologies and Solutions
gmccartney
Posts: 5
Joined: 2012-02-15T13:03:32-07:00
Authentication code: 8675308
Contact:

Re: crop page in multipage tif

Post 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
Gerald McCartney
CGI Technologies and Solutions
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: crop page in multipage tif

Post 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
gmccartney
Posts: 5
Joined: 2012-02-15T13:03:32-07:00
Authentication code: 8675308
Contact:

Re: crop page in multipage tif

Post by gmccartney »

The -clone operator worked perfectly.
Thank you.
Gerald McCartney
CGI Technologies and Solutions
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: crop page in multipage tif

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply