0

I'm trying to get GraphicsMagick to resize my various images into a standard square. The input is always variable - vertical, horizontal images, different sizes etc.

I want to basically have: - A white background canvas @ 600px x 600px - The image sits in the center of that canvas @ 500px x 500px

I've tried so many from the docs but I can't get it working correctly.

This is what I have working so far (JavaScript):

gm(content)
  .autoOrient()
  .resize(600, 600)
  .gravity('Center')
  .extent([600, 600])
  .background('#FFFFFF')
  .flatten();

And it just comes out the correct width, but keeps the ratio so for a rectangle, it comes out at 600px wide and 240px high (as it kept the ratio).

Any help appreciated!

Jonathan Bird
  • 313
  • 5
  • 19
  • 1
    Have you tried the extent example from the GM website? It may be as simple as putting the background before the extent. – Bonzo May 17 '20 at 08:30
  • @Bonzo No luck unfortunately. I tried resize > gravity > background > extent but still comes out without 500px height. – Jonathan Bird May 17 '20 at 23:08
  • @Bonzo Okay so my issue was that I passed in width & height into extent as an array rather than straight params... rookie error. Although no errors thrown which is strange. – Jonathan Bird May 17 '20 at 23:13

1 Answers1

1

The solution to my issue was simply that I set extent as an array. Final solution:

gm(content)
  .autoOrient()
  .resize(550, 550)
  .gravity('Center')
  .background('#FFFFFF')
  .extent(600, 600)
  .flatten();
Jonathan Bird
  • 313
  • 5
  • 19