imagemagickmagickwand

How to keep the image aspect ratio when resize?


For example, when I only provide one of the length or width parameters, another parameter is automatically calculated while maintaining the aspect ratio of the image.

Is there a related function in the MagicWand library? Still have to calculate the aspect ratio yourself?


Solution

  • Is there a related function in the MagicWand library? Still have to calculate the aspect ratio yourself?

    When working with MagickWand C-API, you would be expected to calculate the aspect ratio yourself. There was MagickTransformImage method that supports both cropping & resizing by evaluating a formatted string (including aspect ratios), but that has been deprecated & removed.

    In the MagickCore library, there's ParseMetaGeometry method that will support formatted string w/ aspect ratio flags.