Crop geometry "center-north"
Posted: 2016-11-18T08:44:41-07:00
Hi,
I would like to batch convert images with different oriantations and resolutions. I want to resize and crop them to a square images with the same resolution.
I ran this code on the files, which gave me the expected results: a square image cropped around the center.
This is perfect for most pictures, but some images show a single person in portrait-format, where half the head gets cut off.
So I am looking for a mix of "geometry center" and "geometry north".
I have been using this php-function in the past to get the desired crop.
Can I use Imagemagick alone to achieve this?
I would like to batch convert images with different oriantations and resolutions. I want to resize and crop them to a square images with the same resolution.
Code: Select all
convert intput -resize "435x435^" -gravity center -crop 435x435+0+0 +repage output
This is perfect for most pictures, but some images show a single person in portrait-format, where half the head gets cut off.
So I am looking for a mix of "geometry center" and "geometry north".
I have been using this php-function in the past to get the desired crop.
Code: Select all
//Portrait
$crop_y=($height_orig-$height_new)/6 //("/2" would center the image, "/6" turned out to be the optimal compromise)
imagecopyresampled($dst_img, $src_img, 0, 0, 0, $crop_y, 0, 435, 435, $width_orig, $height_orig)