Rule of thumb: When to use +repage?

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
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

Rule of thumb: When to use +repage?

Post 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!
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

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

Post 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!
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

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

Post 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".
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

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

Post by mhulse »

Thank you so much for the additional tips Fred and GeeMack! This information is super helpful! :)

You guys rock!
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

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

Post 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!!!!
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
Post Reply