Page 1 of 1

gravity

Posted: 2011-12-20T12:16:59-07:00
by blowzy
Is there any way with magick++ to use gravity parameter ( Magick::CenterGravity ) when croping/resizing images? Need to crop from the center (or count pixels to crop from the right/bottom) i.e. something like this gravity parameter from command line

Code: Select all

convert -thumbnail "120x90>" -gravity Center -extent 120x90 monalisa171p.jpg monalisa171p_thumb.jpg 
thanks

Re: gravity

Posted: 2011-12-20T13:07:35-07:00
by magick
The Magick++ extent() method is overloaded and accept a gravity argument. Use one of extent ( const Geometry &geometry_, const GravityType gravity_ ) or extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ ).

Re: gravity

Posted: 2011-12-20T14:10:47-07:00
by blowzy
thanks for the answer. will try how works extent() (because still need to crop from the bottom with offset)

now, for center coping i wrote something like this and use value as crop offset:

Code: Select all

over_pixels_height = floor( ( img.rows() - thumb_height) / 2 );
ps. sorry for my english