Page 1 of 1

Resize while keeping aspect ratio with some options

Posted: 2019-11-25T17:22:44-07:00
by nilambara

I'm getting started with the API and finding some difficulty figuring out how some calls map to command-line parameters. IM 7.0.9 on macOS. The command I'm trying to replicate:

Code: Select all

magick convert -resize 160x160 -background transparent -colorspace srgb -depth 8 -gravity center -extent 160x160 -strip file.pdf[0] …
Command-line parameters are well documented though it seems that the API is less so. For example, I would expect that -resize would act like ResizeImage and allow me to preserve aspect ratio. As the API develops, maybe it would be a good idea to be able to make available all possible command-line options through the API if they aren't yet.

I'm using Go Imagick, the equivalent C commands are listed as comments:

Code: Select all

_ = mw.SetDepth(8)
_ = mw.SetExtract("160x160") // MagickSetExtract

mw.ReadImage(filePath + "[0]")
pixel := imagick.NewPixelWand()
_ = mw.SetImageBackgroundColor(pixel) // MagickSetImageBackgroundColor

_ = mw.SetImageGravity(imagick.GRAVITY_CENTER) // MagickSetImageGravity
_ = mw.SetImageExtent(160, 160)                // MagickSetImageExtent

_ = mw.StripImage()
MagickSetExtract allows me to resize without needing to calculate aspect ratio so I'm using that. Background using either MagickSetGravity or MagickSetImageGravity, and SetImageGravity seem to have no effect. I get a white background with the image left-aligned. I think there was some older thread about gravity not having an effect. I'm not sure if I'm missing something or there are some things not yet implemented. Help would be great.

I'm also open to suggestions if the command should be different, e.g, it seems I need to specify colorspace for it to render correctly.

Re: Resize while keeping aspect ratio with some options

Posted: 2019-11-25T17:34:04-07:00
by snibgo
You posted in a MagickWand subforum. MagickWand is an API for ImageMagick, maintained by the same team.

However, your query is actually about IMagick. This is a separate product, that provides a PHP interface to ImageMagick. IMagick is maintained by a separate team. IMagick may not have an API for all features of ImageMagick, especially recent features.

There is a separate subforum for IMagick, so I have moved your question there.

I know almost nothing about IMagick. See its documentation, eg ... cropZoom=1

Re: Resize while keeping aspect ratio with some options

Posted: 2019-11-25T17:40:06-07:00
by nilambara
I am using the Go package. As there wasn't a forum for it, and all the commands map to C, I had posted there.

Re: Resize while keeping aspect ratio with some options

Posted: 2019-11-25T17:59:14-07:00
by snibgo
The best documentation for MagickWand functions is in the source code. See ... MagickWand . For example, MagickResizeImage() is in magick-image.c. There is generally one MagickWand function per CLI operation.

For further detail, you can go down one level to MagickCore. For example, MagickResizeImage() calls the MagickCore function ResizeImage in resize.c. There you will find all the gory detail.