omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Managing photos

    Pythonista
    2
    31
    6089
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp @frankL last edited by cvp

      @frankL said:

      That doesn't seem to change anything.

      True if your photo is ratio 5/2 with your frame 500,200.

      What do you really want and which is the size width/height of your photo?

      And did you read the doc of ui.ImageView.content_mode?

      1 Reply Last reply Reply Quote 0
      • frankL
        frankL last edited by

        You're right about the photo ratio. It is doing the right thing.

        I've been reading the image section in this doc:
        http://omz-software.com/pythonista/docs/ios/ui.html#image
        Which I just realized is the general section. But I found the Image module documentation (actually the list of all modules which I haven't seen before). I see that I have a lot to learn. Thanks for all of your help.

        cvp 1 Reply Last reply Reply Quote 0
        • cvp
          cvp @frankL last edited by

          @frankL be careful that there are two kinds of images:

          1. ui.Image which is the Pythonista version of UIImage standard iOS image
          2. PIL Image which comes from a Python module named PIL
            The forum contains a lot of topics about tHem and their conversion in both directions.
            Good luck
          1 Reply Last reply Reply Quote 0
          • frankL
            frankL last edited by

            If I have the path to several photos on my iphone, for example:

            /var/mobile/Media/DCIM/131APPLE/IMG_1415.HEIC
            /var/mobile/Media/DCIM/131APPLE/IMG_1412.HEIC
            /var/mobile/Media/DCIM/131APPLE/IMG_1389.HEIC
            /var/mobile/Media/DCIM/131APPLE/IMG_1388.HEIC
            /var/mobile/Media/DCIM/131APPLE/IMG_1373.JPG

            How can I show these as thumbnails in a subview?

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @frankL last edited by cvp

              @frankL said:

              How can I show these as thumbnails in a subview?

              All photos in one view? Or I don't understand

              You have the code to display one in an ImageView. If it has small frame, the photo will be a thumbnail.

              1 Reply Last reply Reply Quote 0
              • frankL
                frankL last edited by

                Yes, all photos in one view. Just like you see when you use
                asset = photos.pick_asset(assets)

                cvp 2 Replies Last reply Reply Quote 0
                • cvp
                  cvp @frankL last edited by cvp

                  @frankL very quick and dirty (up to you to compute correct frame and scales)

                  Or you add one ImageView as subview per photo in your view

                  import ui
                  v = ui.ImageView()
                  v.frame = (0,0,400,100)
                  with ui.ImageContext(400,100) as ctx:
                  	u = ui.Image.named('test:Lenna').draw(0,0,200,100)
                  	u = ui.Image.named('test:Mandrill').draw(200,0,200,100)
                  	v.image = ctx.get_image()
                  v.present('sheet')
                  

                  1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @frankL last edited by cvp

                    @frankL you can also modify this script (try it so) to support your own photos instead of photos from camera roll.
                    Easy modification if you have an array of your paths

                    • self.assets = array of your paths
                    • photo.image = ui.image.named(your array[row])
                    from  objc_util import *
                    import os
                    import photos
                    import ui
                    
                    class PhotosPickerTableView(ui.View):
                    
                    	def __init__(self,w,h,d):
                    		self.width = w
                    		self.height = h
                    		self.selected = None
                    		
                    		ok = ui.ButtonItem()
                    		ok.image = ui.Image.named('iob:ios7_checkmark_outline_32')
                    		ok.action = self.ok_action
                    		self.right_button_items = (ok,)
                    		
                    		tbl = ui.TableView()	
                    		tbl.frame = (0,0,d,h)
                    		tbl.row_height = d
                    		self.assets = photos.get_assets()
                    		tbl.data_source = ui.ListDataSource(items=range(len(self.assets)))
                    		tbl.separator_color=(1,0,0,0)
                    		tbl.delegate = self
                    		tbl.data_source.tableview_cell_for_row = self.tableview_cell_for_row
                    		tbl.background_color = (0,0,0,0)
                    		self.add_subview(tbl)
                    
                    		pha =ui.View(name='photo_area')		
                    		pha.frame = (d,0,w-d,h)
                    		self.add_subview(pha)
                    		img = ui.ImageView(name='selected_photo')
                    		img.frame = (0,0,w-d,h)
                    		img.content_mode=ui.CONTENT_SCALE_ASPECT_FIT
                    		img.background_color = (0.5,0.5,0.5,1)
                    		pha.add_subview(img)
                    		
                    		self.tableview_did_select(tbl,0,0)
                    
                    		self.photo_scale = 1		
                    		
                    	def ok_action(self,sender):
                    		self.close()
                    		
                    	def tableview_did_select(self, tableview, section, row):
                    		ui_image = self.assets[row].get_ui_image()
                    		self['photo_area']['selected_photo'].image = ui_image
                    		self.selected = row
                    		
                    	def tableview_cell_for_row(self,tableview, section, row):
                    		cell = ui.TableViewCell()
                    		v = 0.4 + (row % 2)*0.4
                    		cell.bg_color = (v,v,v,v)
                    		selected_cell = ui.View()
                    		#selected_cell.bg_color = 'blue'
                    		selected_cell.border_width = 2
                    		selected_cell.border_color = 'blue'
                    		cell.selected_background_view = selected_cell
                    		photo = ui.ImageView()
                    		photo.frame = (0,0,tableview.row_height,tableview.row_height)
                    		photo.image = self.assets[row].get_ui_image()
                    		photo.content_mode = ui.CONTENT_SCALE_ASPECT_FIT
                    		cell.content_view.add_subview(photo)
                    		return cell
                    		
                    def main():
                    			
                    	# Hide script
                    	w,h = ui.get_screen_size()
                    	mi = min(w,h)*0.9
                    	my_back = PhotosPickerTableView(mi,mi,100)
                    	my_back.background_color='white'
                    	my_back.name = 'Photos Picker via TableView'	
                    	
                    	my_back.present('sheet',hide_title_bar=False)	
                    	my_back.wait_modal()
                    		
                    # Protect against import	
                    if __name__ == '__main__':
                    	main()
                    
                    1 Reply Last reply Reply Quote 0
                    • frankL
                      frankL last edited by

                      Thank you. That is cool looking. But I don't see where to input my array of paths. When I ran the script, it pulls from my camera roll.

                      cvp 1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @frankL last edited by

                        @frankL

                        from  objc_util import *
                        import os
                        import photos
                        import ui
                        
                        class PhotosPickerTableView(ui.View):
                        
                            def __init__(self,w,h,d):
                                self.width = w
                                self.height = h
                                self.selected = None
                                
                                ok = ui.ButtonItem()
                                ok.image = ui.Image.named('iob:ios7_checkmark_outline_32')
                                ok.action = self.ok_action
                                self.right_button_items = (ok,)
                                
                                tbl = ui.TableView()    
                                tbl.frame = (0,0,d,h)
                                tbl.row_height = d
                                self.assets = ['test:Lenna','test:Mandrill','test:Numbers','test:Pattern','test:Peppers','test:Boat','test:Bridge','test:Sailboat']
                                tbl.data_source = ui.ListDataSource(items=range(len(self.assets)))
                                tbl.separator_color=(1,0,0,0)
                                tbl.delegate = self
                                tbl.data_source.tableview_cell_for_row = self.tableview_cell_for_row
                                tbl.background_color = (0,0,0,0)
                                self.add_subview(tbl)
                        
                                pha =ui.View(name='photo_area')     
                                pha.frame = (d,0,w-d,h)
                                self.add_subview(pha)
                                img = ui.ImageView(name='selected_photo')
                                img.frame = (0,0,w-d,h)
                                img.content_mode=ui.CONTENT_SCALE_ASPECT_FIT
                                img.background_color = (0.5,0.5,0.5,1)
                                pha.add_subview(img)
                                
                                self.tableview_did_select(tbl,0,0)
                        
                                self.photo_scale = 1        
                                
                            def ok_action(self,sender):
                                self.close()
                                
                            def tableview_did_select(self, tableview, section, row):
                                ui_image = ui.Image.named(self.assets[row])
                                self['photo_area']['selected_photo'].image = ui_image
                                self.selected = row
                                
                            def tableview_cell_for_row(self,tableview, section, row):
                                cell = ui.TableViewCell()
                                v = 0.4 + (row % 2)*0.4
                                cell.bg_color = (v,v,v,v)
                                selected_cell = ui.View()
                                #selected_cell.bg_color = 'blue'
                                selected_cell.border_width = 2
                                selected_cell.border_color = 'blue'
                                cell.selected_background_view = selected_cell
                                photo = ui.ImageView()
                                photo.frame = (0,0,tableview.row_height,tableview.row_height)
                                photo.image = ui.Image.named(self.assets[row])
                                photo.content_mode = ui.CONTENT_SCALE_ASPECT_FIT
                                cell.content_view.add_subview(photo)
                                return cell
                                
                        def main():
                                    
                            # Hide script
                            w,h = ui.get_screen_size()
                            mi = min(w,h)*0.9
                            my_back = PhotosPickerTableView(mi,mi,100)
                            my_back.background_color='white'
                            my_back.name = 'Photos Picker via TableView'    
                            
                            my_back.present('sheet',hide_title_bar=False)   
                            my_back.wait_modal()
                                
                        # Protect against import    
                        if __name__ == '__main__':
                            main()
                        
                        1 Reply Last reply Reply Quote 0
                        • frankL
                          frankL last edited by

                          That's awesome! Thank you

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors