How to zoom with convert crop and resize

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
Pyx

How to zoom with convert crop and resize

Post by Pyx »

I using the Bash command line and ImageMagick 6.2.4.5

If I type;

convert Starter.ppm -resize 100% -crop 725x200+275+450 Result1.ppm

This command cuts out the size and the area of Starter.ppm that I want and saves it in Result1.ppm

If I type;

convert Starter.ppm -resize 200% -crop 725x200+275+450 Result2.ppm

This command does cut the size of Starter.ppm that I want BUT it "zooms in" upwards and to the left of Starter.ppm
saved in Result1.ppm

I DO want to zoom in but, I DO NOT want to move upwards and to the left in the result. How do I avoid this ?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to zoom with convert crop and resize

Post by Bonzo »

It is to do with your offset +275+450 which is the distance from the top left corner. It will be different in both examples as you are cropping after resizing.

I would change +275+450 to +550+900 or do the crop first then resizing.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to zoom with convert crop and resize

Post by anthony »

The crop offset is for the top left corner, and you have fixed this.

You can in the latest versions of IM do a zoom centered on a particular point using
the ScaleRotateTranslate distortion method.

Code: Select all

   convert Starter.ppm  -interpolate bicubic \
                -set option:distort:viewport 724x200-362-100 \
                -distort SRT '275,450  2 0 0,0'    result.ppm
The 'viewport' is what part of the distorted image space you are looking at
and is basically the 'crop' which is centered on the origin.

the distrort SRT operation, centers its scales and rotates to 275,450 (or whatever you want), the doubles the image size '2' (zoom), does no rotate '0', then moves that
center rto the origin (0,0) wcih is the middle of your viewing window or 'viewport'.

yes it looks complex, but it will work, and will let you pan, zoom, and rotate the image all in one operation.
See IM Examples, Distorts, General Distortion Operator, for details...
http://imagemagick.org/Usage/distorts/#distort

CAVAT! -distort is still in development. As a consequence, I have not finished the quality handling of its scaling (resize) filters. However as you are zooming, the -interpolation setting is the filter control, and not minification filters I am currently working on.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply