Page 1 of 1

Rule of thumb: When to use +repage?

Posted: 2019-04-10T18:28:39-07:00
by mhulse
Hello,

The docs I could find say:
Use +repage to completely remove/reset the virtual canvas meta-data from the images.
Is there a rule of thumb for when to +repage? For example, this command:

Code: Select all

magick \
  convert \
  pano.jpg \
  -virtual-pixel mirror  \
  -background black \
  -roll +50%+0% \
  +repage \
  -rotate 180 \
  +repage \
  +distort polar 0 \
  +repage \
  tiny-planet.jpg
(Related: viewtopic.php?f=1&t=35817)

Is the use of +repage overkill in the above example?

Does the use of +repage make the conversion faster?

Thanks!

Re: Rule of thumb: When to use +repage?

Posted: 2019-04-10T20:15:54-07:00
by fmw42
Use it generally when saving to a file that keeps the virtual canvas such as PNG. JPG does not need it.

Use typically after -crop or -trim or after distortions or rotations.

One case where you might not want to use it is if you want to crop an image into pieces and then later put them back together.

Re: Rule of thumb: When to use +repage?

Posted: 2019-04-10T20:28:18-07:00
by mhulse
Awesome! Thank you Fred! That's very helpful.

Also, I'm reading up on "virtual canvas" now:

https://www.imagemagick.org/Usage/basic ... ual_canvas

Much appreciated!

Re: Rule of thumb: When to use +repage?

Posted: 2019-04-10T21:10:05-07:00
by fmw42
Note that -roll does not need +repage since it does not change the image size. Typically you might need +repage for commands that change the image size, such as rotation, distortion, and especially crop and trim. I do not think resize needs it. At least I have never needed it for that kind of operation. Also -layers merge needs it.

Re: Rule of thumb: When to use +repage?

Posted: 2019-04-10T21:15:16-07:00
by GeeMack
fmw42 wrote: 2019-04-10T21:10:05-07:00 Typically you might need +repage for commands that change the image size, such as rotation, distortion, and especially crop and trim. I do not think resize needs it. At least I have never needed it for that kind of operation. Also -layers merge needs it.
I also usually do a "+repage" after "-append", "+append", -smush", and "+smush".

Re: Rule of thumb: When to use +repage?

Posted: 2019-04-10T21:35:18-07:00
by mhulse
Thank you so much for the additional tips Fred and GeeMack! This information is super helpful! :)

You guys rock!

Re: Rule of thumb: When to use +repage?

Posted: 2019-04-11T03:04:10-07:00
by snibgo
"+repage" should be used if the image might have virtual canvas metadata, and you don't want it. It is metadata only, and doesn't affect pixels, so it is very fast.

In your example, the jpg input can't have that metadata, and "-roll" can't create it, so the first "+repage" is superfluous.

"-rotate" does generally change that metadata but "-rotate 180" doesn't.

"-distort polar 0" also doesn't change that metadata.

So, yes, all three occurrences of "+repage" in that command are overkill.

Re: Rule of thumb: When to use +repage?

Posted: 2019-04-15T02:50:57-07:00
by mhulse
snibgo wrote: 2019-04-11T03:04:10-07:00 So, yes, all three occurrences of "+repage" in that command are overkill.
Awesome! Thank you so much for the help snibgo.

I removed repage from my script. Currently, I'm only rotating between 0 or 180, and I think I read that imagemagick will ignore 0 for rotate as it's not doing anything (my wrapper script is defaulting to 0 vs. adding code to remove the line from the command string).

Thanks again everyone, I REALLY appreciate the help!!!!