Center abstract shapes to the centre of the picture

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
aleg
Posts: 2
Joined: 2011-08-02T07:35:50-07:00
Authentication code: 8675308

Center abstract shapes to the centre of the picture

Post by aleg »

Hi,

For an experiment I need to use a big number of abstract shapes (white shapes on black background) all different from each other that are not correctly placed in the center of the picture. Since this is very important for the stimuli presentation, I wonder if there is a way for automatically, let's say, crop the shape and place it in the center (usign "gravity" or something) for example a function that detects the border of the shape or something like this. How would you solve this problem in ImageMagick?

Hope you can help me with this,
Thanks
Best

Ale

P.S. I don't know if relevant but I'm using a Mac
aleg
Posts: 2
Joined: 2011-08-02T07:35:50-07:00
Authentication code: 8675308

Re: Center abstract shapes to the centre of the picture

Post by aleg »

Solution found:

convert mypic.png -trim mypic1.png
Done!

Ale
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Center abstract shapes to the centre of the picture

Post by anthony »

WARNING. add a +repage after the -trim to remove the 'crop information' that is saved as a virtual canvas size and position.

If you need them all centered on a standard image size follow the +repage with a -gravity center -extent {WIDTH}x{HEIGHT}.

For example

Code: Select all

convert mypic.png -trim +repage -gravity center -extent 200x200 mypic1.png
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply