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.


    Crop ui.Image

    Pythonista
    3
    5
    2007
    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.
    • pavlinb
      pavlinb last edited by

      Is there a away to crop ui.Image ? I need to avoid converting to PIL image and back to ui.Image.

      Thanks.

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

        @pavlinb

        take a look at this thread and see if this is your issue.

        other than that... without using PIL all i could find was inside photos module.. make sure if you test this example you have a JPEG in your current directory called temp.jpg...

        import ui
        import photos
        
        img=photos.create_image_asset('./temp.jpg').get_ui_image(size=(512,512), crop=True)
        
        v=ui.View(frame=(0, 0, 600, 800))
        iv=ui.ImageView(image=img)
        v.add_subview(iv)
        
        v.present('sheets')
        

        hope this helps.

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

          @pavlinb try

          ui_image = ui.Image.named('test:Lenna')
          ui_image.show()
          w,h = ui_image.size
          wc,hc = w/2,2*h/3
          with ui.ImageContext(wc,hc) as ctx:
          	ui_image.draw(-60,-20,w,h)
          	ui_image = ctx.get_image()
          ui_image.show() 
          
          stephen pavlinb 2 Replies Last reply Reply Quote 1
          • stephen
            stephen @cvp last edited by

            @cvp said:

            @pavlinb try

            ui_image = ui.Image.named('test:Lenna')
            ui_image.show()
            w,h = ui_image.size
            wc,hc = w/2,2*h/3
            with ui.ImageContext(wc,hc) as ctx:
            	ui_image.draw(-60,-20,w,h)
            	ui_image = ctx.get_image()
            ui_image.show() 
            

            aweome! i figured ImageContext was the one but couldnt think of how to position croping

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

              @cvp It seems that your example helps a lot.

              Thanks.

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