3

Does Node gm have built-in support for resizing an image while preserving aspect ratio (ie., generating a thumbnail)? Or should I get the image size, calculate the proper ratio, and then call resize?

This question is inspired by PIL's similar functionality.

Community
  • 1
  • 1
ty.
  • 10,924
  • 9
  • 52
  • 71
  • 6
    just use `gm().resize(maxSize)`. it automatically resizes so that the image's max dimension is `maxSize`. – Jonathan Ong Sep 16 '12 at 06:17
  • Thanks, that's what I was looking for. Do you want to add it as an answer and I'll accept it? – ty. Sep 16 '12 at 06:32
  • @JonathanOng where is `maxSize` defined? – asus Sep 09 '19 at 20:52
  • @asus According to the latest node gm api docs, `resize` takes the width in pixels. You can also call `gm().resize(width, height)`. See https://aheckmann.github.io/gm/docs.html. – ty. Sep 10 '19 at 00:06
  • ah your comment is from 2012..things have changed. I am passing both `width` and `height` as specified by the docs but thought I may have missed the `maxSize` arg that you 2 were discussing thanks – asus Sep 10 '19 at 00:12

1 Answers1

2

Jonathan's comment is the solution:

gm().resize(maxSize)

This resizes the image to width maxSize. See the relevant documentation.

ty.
  • 10,924
  • 9
  • 52
  • 71