Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Take a square photo
-
Hello, is there a way to use photos.capture_image() to take a square photo instead?
-
@ChelsWin I don't think that you can force the camera to a square via photos.capture_image but you could use this kind of script which uses camera and then an Apple standard view that shows the photo in a forced square. I'm sure that I am not clear enough, thus try it.
import ui from objc_util import * #import ctypes #from PIL import Image def imagePickerController_didFinishPickingMediaWithInfo_(self,cmd,picker,info): global view pick = ObjCInstance(picker) # Set delegate to nil, and release its memory: pick.setDelegate_(None) ObjCInstance(self).release() # Dismiss the sheet: pick.dismissViewControllerAnimated_completion_(True, None) # Get UIImage infos = ObjCInstance(info) #print(infos) img = infos['UIImagePickerControllerEditedImage'] # UIImage UIImagePNGRepresentation = c.UIImagePNGRepresentation UIImagePNGRepresentation.restype = c_void_p UIImagePNGRepresentation.argtypes = [c_void_p] UIImage_data = nsdata_to_bytes(ObjCInstance(UIImagePNGRepresentation(img))) ui_image = ui.Image.from_data(UIImage_data) view['iv'].image = ui_image SUIViewController = ObjCClass('SUIViewController') MyPickerDelegate = create_objc_class('MyPickerDelegate', methods=[imagePickerController_didFinishPickingMediaWithInfo_], protocols=['UIImagePickerControllerDelegate']) class Extracter(ui.View): def __init__(self): self.background_color = 'white' self.frame = (0,0,400,400) # Take Photo Button self.take_photo = ui.ButtonItem(title = 'Take Photo') self.right_button_items = (self.take_photo,) self.take_photo.action = self.take_photo_action iv = ui.ImageView(name='iv') iv.frame = (0,0,self.width,self.height) self.add_subview(iv) # Take Photo Action #@ui.in_background @on_main_thread def take_photo_action(self, sender): # Show camera picker = ObjCClass('UIImagePickerController').alloc().init() delegate = MyPickerDelegate.alloc().init() picker.setDelegate_(delegate) picker.allowsEditing = True picker.sourceType = 1 # UIImagePickerControllerSourceTypeCamera picker.setAllowsEditing_(True) #print(dir(picker)) super_view = self super_view_pntr = ObjCInstance(super_view) vc = SUIViewController.viewControllerForView_(super_view_pntr) vc.presentModalViewController_animated_(picker, True) # Protect against import if __name__ == '__main__': global view view = Extracter() view.present('sheet')
-
@cvp Thank you. That solved my problem