differences between -resize and -size, and between -repage and -page for convert?

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
Tim
Posts: 14
Joined: 2014-11-15T12:39:34-07:00
Authentication code: 6789

differences between -resize and -size, and between -repage and -page for convert?

Post by Tim »

For Imagick's `convert`, what are the differences

- between `-resize` and `-size`, and
- between `-repage` and `-page`?

If I want to convert some png files to a pdf file, and change the size of images (as number of pixels, or as some standard page size such as A4), which options shall I use? (It seems like `-page a4` works as it intends to, while `-repage a4` doesn't make any change. I haven't figured out the other two yet.)


From its manpage

-size geometry width and height of image

-resize geometry resize the image

-page geometry size and location of an image canvas (setting)

-repage geometry size and location of an image canvas
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: differences between -resize and -size, and between -repage and -page for convert?

Post by Bonzo »

Code: Select all

Convert -size 500x500 xc:white output.jpg
Will create a white jpg 500px x 500px

Code: Select all

Convert input.jpg -resize 500x500 xc:white output.jpg
Will resize an image so its longest side is 500px keeping the aspect ratio
Tim
Posts: 14
Joined: 2014-11-15T12:39:34-07:00
Authentication code: 6789

Re: differences between -resize and -size, and between -repage and -page for convert?

Post by Tim »

Do you mean -size and -page resize to the height and width exactly as specified, while -resize and -repage resize as close to specified as possible but preserving aspect ratio?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: differences between -resize and -size, and between -repage and -page for convert?

Post by Bonzo »

Size is the size of a new canvas and resize changes the size of an image. You can set the -resize options to effect the outcome; see http://www.imagemagick.org/script/comma ... p#geometry

I do not use -page and -repage a lot but -page can be used to set the position of sub images on another image when using layers.

Check out Anthony's examples: http://www.imagemagick.org/Usage/
There is an index for some of the operators at the bottom of the left index column.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: differences between -resize and -size, and between -repage and -page for convert?

Post by snibgo »

Tim: I suggest you read the descriptions on http://www.imagemagick.org/script/comma ... ptions.php , and experiment with them.

"-resize" is an operation that expands or shrink images in the current list. It changes the actual pixels. None of the others do.

"-size" is a setting that will be used for for the size of new images created (eg with xc: or canvas:).

"-page" is a setting that will change canvas settings (size and offset) of following images, whether they are xc: or read from file etc. (If there are no following images, it instead changes canvas settings of images in the current list. I'm not sure if this is good behaviour.)

"-repage" is an operation that changes canvas settings of images in the current list. It does not affect future images.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: differences between -resize and -size, and between -repage and -page for convert?

Post by fmw42 »

-page also is used in a different context to specify a certain size for resizing according to the media table listed below it at http://www.imagemagick.org/script/comma ... s.php#page. So it will do resizing, but I have no idea if it just makes calls to -resize or uses some other method such as -scale or -sample or something totally different.

-page and -repage are used to adjust the position of the image on its virtual canvas. -page is used before an operator such as -flatten. -repage is used afterwards, but is mostly used in the +repage form to remove any virtual canvas.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: differences between -resize and -size, and between -repage and -page for convert?

Post by snibgo »

-page also is used in a different context to specify a certain size for resizing according to the media table listed below it at http://www.imagemagick.org/script/comma ... s.php#page. So it will do resizing, but I have no idea if it just makes calls to -resize or uses some other method such as -scale or -sample or something totally different.
Does "-page" resize? If the output is PDF, it will set the size of each page but doesn't (I think) resize the image.
snibgo's IM pages: im.snibgo.com
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: differences between -resize and -size, and between -repage and -page for convert?

Post by pipitas »

Maybe this answer on Stackoverflow is also helpful for one part of your question:

"What's the difference of sample/resample/scale/resize/adaptive-resize/thumbnail ImageMagick convert?"
http://stackoverflow.com/a/13078621/359307
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: differences between -resize and -size, and between -repage and -page for convert?

Post by fmw42 »

Does "-page" resize? If the output is PDF, it will set the size of each page but doesn't (I think) resize the image.
I do not really know. I hardly ever use -page for resizing. I only really use it for -flatten.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: differences between -resize and -size, and between -repage and -page for convert?

Post by anthony »

-page is meant only to provide settings for image that are being read in.

In most cases only the 'position' of the image being read in is set (for layering images on a larger 'virtual canvas'), but also set the size of that virtual canvas. That is override any 'default' virtual canvas information on images read in later.

A few image formats also use the size of the 'page' setting for various effects, most notiabbly for postscript, and PDF image file formats. It was this that defined the options name of 'page' as in page size (like a printer).

-repage in its various forms are ment to control images the images position and virutla canvas that are already in memory. Some 'flags' also let you re-position images relative to there old position on the virtual canvas.

See IM Examples.. Basics... Page, Repage, and the Virtual Canvas
http://www.imagemagick.org/Usage/basics/#page


-size is only meant to set the size of new images IM may generate (Canvases)
http://www.ict.griffith.edu.au/anthony/canvas/#solid

However it also used to also effect JPEG image reading, but that was seperated using a format specific define instead, as it was confusing.
http://www.imagemagick.org/Usage/formats/#jpg_read

-resize and -distort resize are purely a operation, modifying existing images, resulting changing the overall size of the image in pixels. Basically a Image Distortion. The two techniques while closely related do it in very different ways. -resize does it in a common 'fast' to pass method, that first resizes the image on one axis to a intermediate image (never seen), then in the other axis. It is limited to resizing images by whole pixel counts. The -distort normally does not have those limitations and applyed the distortion as a single pass. The '-distort resize' re-instates the same 'whole pixel count' limitations.
http://www.imagemagick.org/Usage/resize/

There are LOTS of wany images can be 'resized' or scaled, that are not so common. and hundreds of effected and modifications that you can use to adjust the operations, and results.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply