Reputation: 1678
from PIL import Image
img=Image.open('/home/ahmed/internship/cnn_ocr/image1.png')
img.size
(2458, 3504)
But when l try to crop the image as follow :
img.crop(414,122,650,338)
l got the following error :
Traceback (most recent call last):
File "/usr/lib/python3.5/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
TypeError: crop() takes from 1 to 2 positional arguments but 5 were given
But crop()
takes 4 parameter : left, top, right, bottom. What's wrong
Upvotes: 3
Views: 8537
Reputation: 107
I am also facing a same error.
x = 0 y = 0 w = 1000/3 h = 667/10 mac.crop(x,y,w,h)
TypeError: crop() takes from 1 to 2 positional arguments but 5 were given
After, i tried below code get an output
mac.crop((x,y,w,h))
Make sure you are try again, below mentioned code to get a clear result.
img.crop((414,122,650,338))
Upvotes: 0
Reputation: 477160
No crop
takes one explicit parameter: a 4-tuple (and implicitly of course the self
). The documentation states:
Image.crop(box=None)
Returns a rectangular region from this image. The
box
is a 4-tuple defining the left, upper, right, and lower pixel coordinate.Note: Prior to Pillow 3.4.0, this was a lazy operation.
Parameters:
box
- The crop rectangle, as a (left, upper, right, lower)-tuple.
Return type: Image
Returns: An Image object.
(formatting added)
So you should rewrite it to:
img.crop((414,122,650,338))
# ^ 4-tuple ^
Furthermore you better assign the output to a variable (possibly img
itself):
some_other_img = img.crop((414,122,650,338))
Upvotes: 16