ImageMagick: how to minimally crop an image to a certain aspect ratio?

Imagemagick 7.0.7.22 and above -crop 3:2 works since January 6th, 2018. JPG magick convert in.jpg -gravity center -crop 3:2 out.jpg Warning/reminder: if you don’t use -gravity center, you will get two output files: PNG As fmw42 points out, PNG files store the virtual canvas size. +repage is recommended. magick convert in.png -gravity center -crop 3:2 … Read more

Set dimensions for UIImagePickerController “move and scale” cropbox

Not possible with UIImagePickerController unfortunately. The solution I recommend is to disable editing for the image picker and handle it yourself. For instance, I put the image in a scrollable, zoomable image view. On top of the image view is a fixed position “crop guide view” that draws the crop indicator the user sees. Assuming … Read more

How can I crop an image in Qt?

You can use QPixmap::copy: QRect rect(10, 20, 30, 40); QPixmap original(‘image.png’); QPixmap cropped = original.copy(rect); There is also QImage::copy: QRect rect(10, 20, 30, 40); QImage original(‘image.png’); QImage cropped = original.copy(rect);

crop center portion of a numpy image

Something along these lines – def crop_center(img,cropx,cropy): y,x = img.shape startx = x//2-(cropx//2) starty = y//2-(cropy//2) return img[starty:starty+cropy,startx:startx+cropx] Sample run – In [45]: img Out[45]: array([[88, 93, 42, 25, 36, 14, 59, 46, 77, 13, 52, 58], [43, 47, 40, 48, 23, 74, 12, 33, 58, 93, 87, 87], [54, 75, 79, 21, 15, 44, … Read more