Page 1 of 1

Center abstract shapes to the centre of the picture

Posted: 2011-08-02T07:43:43-07:00
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

Re: Center abstract shapes to the centre of the picture

Posted: 2011-08-02T08:11:11-07:00
by aleg
Solution found:

convert mypic.png -trim mypic1.png
Done!

Ale

Re: Center abstract shapes to the centre of the picture

Posted: 2011-08-02T18:26:32-07:00
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