Page 1 of 1

moving pages from one multipage tiff to another

Posted: 2012-02-15T16:14:38-07:00
by gmccartney
I am moving pages from one tif to another.

Moving one page works great. This command inserts page 2 from file2.tif into file1.tif as page 2 of the result.tif:
convert file1.tif file2.tif[1] -insert 1 result.tif

But if I try to move a range of pages, onyl the first page goes to the correct destination. The rest go to the end of the file.
This command inserts page 2 from file2.tif into file1.tif as page 2, but then adds page 3 from file2.tif as the last page of the result.tif:
convert file1.tif file2.tif[1-2] -insert 1 result.tif

Does the -insert operator process ranges differently?

Gerald

Re: moving pages from one multipage tiff to another

Posted: 2012-02-15T17:59:39-07:00
by fmw42
see http://www.imagemagick.org/Usage/basics/#insert

I believe that insert only works with one image at a time.


"The "-insert" operation is sort of the opposite of "-delete". It will take the last image in the current image sequence and insert so that it is positioned at the given index."

So you will have to do multiple -insert in the same command line.

Re: moving pages from one multipage tiff to another

Posted: 2012-02-15T22:44:48-07:00
by anthony
As an alternative try this...

Code: Select all

convert 'file1.tif[0]'   'file2.tif[1-2]'  'file1.tif[1-]'   result.tif
yes it reads the first image twice, but it will do the job.

Another alternative with just one read.

Code: Select all

convert file1.tif \(  -clone 0  file2.tif  -clone 1--1 -write  result.tif \) null:
Note that the actual write is in the middle of the command, not at the end.

Looks like we need something to swap between the current image list and the 'pushed' image list
to really solve this problem nicely.


Third solution, using MPR: which is a image list saver

Code: Select all

convert file1.tif -write MPR:images -delete 0--1 \
         'MPR:images[0]'  file2.tif  MPR:images[1--1]' result.tif 
See IM Examples, File Handling, MPR
http://www.imagemagick.org/Usage/files/#mpr

Re: moving pages from one multipage tiff to another

Posted: 2012-02-16T07:57:16-07:00
by gmccartney
hmmm, so if the users asks to move pages 1,3 and 5 from file 1 to file2 after page 3 could I use:

convert file1.tif -write MPR:file1 +delete file2.tif -write MPR:file2 +delete \
MPR:file2[0-2] MPR:file1[0] MPR:file1[2] MPR:file1[4] MPR:file1[3--1] result.tif

I will have to try that...

Gerald

Re: moving pages from one multipage tiff to another

Posted: 2012-02-16T19:38:13-07:00
by anthony
Yeap. The mpr: image save memory is very efficient as it clones the image list.

That means image data is not copied only refered to, until you actually modify images, which you are not doing.