-gravity Centre -crop 100x100 no output

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
astrobob
Posts: 2
Joined: 2017-06-02T19:14:07-07:00
Authentication code: 1151

-gravity Centre -crop 100x100 no output

Post by astrobob »

Hi all

I have hundreds of images from time lapse astronomy of Jupiter that I have rotated by different angles to correct for telescope rotation. They are saved as tifs but have different canvas sizes depending on how much they are rotated. Now all I need to do is crop a rectangle from the middle of each to make into a video of Jupiters moons and red spot moving. I have a vbs script that has successfully used IM to rotate the 700 or so images the correct amount but I cannot get the cropping to work properly.

I am using 64 bit windows 10 with ImageMagick 7.0.5-7 x64 2017-05-20

I have experimented with the syntax from the windows command line: (in.tif is a 3508x4492 image)

magick C:\IMtest\in.tif -crop 1280x720 C:\IMtest\out.tif

crops ok but of course gets the top left corner of the original image

What I want is

magick C:\IMtest\in.tif -gravity Center -crop 1280x720 C:\IMtest\out.tif

but I still get the top left corner of the image. -gravity Centre has no effect on the crop.

What am I doing wrong?

Bob
astrobob
Posts: 2
Joined: 2017-06-02T19:14:07-07:00
Authentication code: 1151

Re: -gravity Centre -crop 100x100 no output

Post by astrobob »

Ah ha!

I have just hit the answer

magick C:\IMtest\in.tif -gravity Center -crop 1280x720+0+0 C:\IMtest\out.tif works!

It needs the offsets specified.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: -gravity Centre -crop 100x100 no output

Post by GeeMack »

astrobob wrote: 2017-06-02T22:17:18-07:00I have just hit the answer

magick C:\IMtest\in.tif -gravity Center -crop 1280x720+0+0 C:\IMtest\out.tif works!

It needs the offsets specified.
The "-crop" operator can output one or more images depending on the input image dimensions, the crop arguments, the gravity setting, and the offset arguments. Also keep in mind the "-extent" operator which works a lot like "-crop" but is sometimes simpler to use and will output just a single image.

The "-extent" operator obeys "-gravity" and will modify the size of the viewport, cropping it smaller or adding more area filled with the "-background" color as necessary. It can take arguments that include offsets, but with most common uses of "-extent" they won't be needed. Your command would look something like this...

Code: Select all

magick C:\IMtest\in.tif -gravity Center -extent 1280x720 C:\IMtest\out.tif
Find out more about using "-extent" at THIS link.
Post Reply