PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 6, 2022

[FIXED] How to set coordinates when cropping an image with PIL?

 May 06, 2022     image, image-processing, python, python-2.7, python-3.x     No comments   

Issue

I don't know how to set the coordinates to crop an image in PILs crop():

from PIL import Image
img = Image.open("Supernatural.xlsxscreenshot.png")
img2 = img.crop((0, 0, 201, 335))
img2.save("img2.jpg")

I tried with gThumb to get coordinates, but if I take an area which I would like to crop, I can only find position 194 336. Could someone help me please?

This is my picture:

enter image description here

I wish to crop to this:

enter image description here


Solution

How to set the coordinates to crop

In the line:

img2 = img.crop((0, 0, 201, 335))

the first two numbers define the top-left coordinates of the outtake (x,y), while the last two define the right-bottom coordinates of the outtake.

Cropping your image

To crop your image like you show, I found the following coordinates: top-left: (200, 330), and right-bottom: (730, 606). Subsequently, I cropped your image with:

img2 = img.crop((200, 330, 730, 606))

enter image description here

with the result:

enter image description here



Answered By - Jacob Vlijm
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing