crop
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
Simple cropping with Paperclip
You only need to use # instead of > as a parameter: has_attached_file :picture, :styles => { :thumb => “200×200#” }
Automatically cropping an image with python/PIL
Install Pillow pip install Pillow and use as from PIL import Image image=Image.open(‘L_2d.png’) imageBox = image.getbbox() cropped = image.crop(imageBox) cropped.save(‘L_2d_cropped.png’) When you search for boundaries by mask=imageComponents[3], you search only by blue channel.
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 an image in the centre using PIL
Assuming you know the size you would like to crop to (new_width X new_height): import Image im = Image.open(<your image>) width, height = im.size # Get dimensions left = (width – new_width)/2 top = (height – new_height)/2 right = (width + new_width)/2 bottom = (height + new_height)/2 # Crop the center of the image im … Read more
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