473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PIL question about crop method

I might be way off target even looking into this method for what I need
to do, but I'm still a little confused about the description of it:

crop
im.crop(box) => image

Returns a rectangular region from the current image. The box is a
4-tuple defining the left, upper, right, and lower pixel coordinate.

I'm probably just being a little dense again, but how exactly do you
write the tuple? Wouldn't a coordinates parameter be a tuple of tuples?
It sounds like here you only need four numbers, but I don't understand
what 'left, upper, right, and lower pixel coordinate' means. It doesn't
seem like it's asking for a set of coordinates for each corner of the
box, or for a set at all. How do four separate numbers make up coordinates?

Thanks.
Apr 5 '06 #1
6 8587
John Salerno schrieb:
I might be way off target even looking into this method for what I need
to do, but I'm still a little confused about the description of it:

crop
im.crop(box) => image

Returns a rectangular region from the current image. The box is a
4-tuple defining the left, upper, right, and lower pixel coordinate.

I'm probably just being a little dense again, but how exactly do you
write the tuple? Wouldn't a coordinates parameter be a tuple of tuples?
It sounds like here you only need four numbers, but I don't understand
what 'left, upper, right, and lower pixel coordinate' means. It doesn't
seem like it's asking for a set of coordinates for each corner of the
box, or for a set at all. How do four separate numbers make up coordinates?


You can think of a rect as two coordinates - e.g. (10, 20), (30, 100)

Alternatively you can see it as boundary lines, in the order left, top,
right, bottom.

(10, 20, 30, 100)

The latter is what you need.

Diez
Apr 5 '06 #2
John Salerno wrote:
I might be way off target even looking into this method for what I need
to do, but I'm still a little confused about the description of it:

crop
im.crop(box) => image

Returns a rectangular region from the current image. The box is a
4-tuple defining the left, upper, right, and lower pixel coordinate.

I'm probably just being a little dense again, but how exactly do you
write the tuple? Wouldn't a coordinates parameter be a tuple of tuples?
It sounds like here you only need four numbers, but I don't understand
what 'left, upper, right, and lower pixel coordinate' means. It doesn't
seem like it's asking for a set of coordinates for each corner of the
box, or for a set at all. How do four separate numbers make up coordinates?

Thanks.

If you want the cropped rectangle to go from 100 to 200 in x and 300 to
400 in y, then those four values need to be placed in a tuple in the
specified order:
box=(100,300,200,400)

Gary Herron

Apr 5 '06 #3
Diez B. Roggisch wrote:
Alternatively you can see it as boundary lines, in the order left, top,
right, bottom.

(10, 20, 30, 100)


So in the above, from where are the numbers being counted? 10 is ten
pixels from the left border of the image? 20 is twenty pixels from the
top border? But is 30 thirty pixels from the left or the right border of
the image? And is 100 one hundred pixels from the top or bottom?
Apr 5 '06 #4
John Salerno wrote:
Diez B. Roggisch wrote:
Alternatively you can see it as boundary lines, in the order left,
top, right, bottom.

(10, 20, 30, 100)


So in the above, from where are the numbers being counted? 10 is ten
pixels from the left border of the image? 20 is twenty pixels from the
top border? But is 30 thirty pixels from the left or the right border of
the image? And is 100 one hundred pixels from the top or bottom?


I came up with this, is it correct:

(a,b) (c,b)
-----------------
| |
| |
-----------------
(a,d) (c,d)
So the tuple would be (a, b, c, d)?
Apr 5 '06 #5
Yes


John Salerno wrote:
John Salerno wrote:
Diez B. Roggisch wrote:
Alternatively you can see it as boundary lines, in the order left,
top, right, bottom.

(10, 20, 30, 100)


So in the above, from where are the numbers being counted? 10 is ten
pixels from the left border of the image? 20 is twenty pixels from the
top border? But is 30 thirty pixels from the left or the right border of
the image? And is 100 one hundred pixels from the top or bottom?


I came up with this, is it correct:

(a,b) (c,b)
-----------------
| |
| |
-----------------
(a,d) (c,d)
So the tuple would be (a, b, c, d)?


Apr 5 '06 #6
John Salerno wrote:
John Salerno wrote:

Diez B. Roggisch wrote:
Alternatively you can see it as boundary lines, in the order left,
top, right, bottom.

(10, 20, 30, 100)

So in the above, from where are the numbers being counted? 10 is ten
pixels from the left border of the image? 20 is twenty pixels from the
top border? But is 30 thirty pixels from the left or the right border of
the image? And is 100 one hundred pixels from the top or bottom?


I came up with this, is it correct:

(a,b) (c,b)
-----------------
| |
| |
-----------------
(a,d) (c,d)
So the tuple would be (a, b, c, d)?

That look right.

But why be so cautious? Try it and see if it works. (I believe it will
-- but if not -- try again.)

Gary Herron
Apr 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kevin Smith | last post by:
Is there a way to "auto-crop" an image in PIL? I have some PNG images with white backgrounds that I want cropped to show only the non-white portion in the center, but I don't see how I can do...
6
by: isaacyho | last post by:
Is there a fast way to crop a vector? I have a vector of size n, and want to reduce it to some subregion (x,y ). Seems like you shouldn't have to recopy all of those elements into a new vector,...
1
by: Jazper | last post by:
hi how can i Insert, change and crop META-Tags auf a Webform programmtechnically? Regards Jazper
3
by: ACaunter | last post by:
Hi there, I was wondering if there was a way to crop a peice of an ASP.Net Image, allowing the user to zoom in on only a section of the picture?? any help would be appreciated!! thanks --...
4
by: Crirus | last post by:
I have a square picture. I need to draw a circle on it, and everything outside that circle to be set to a certain color, so the image looks framed On other words, I want to crop a circle form a...
1
by: arunbalait | last post by:
I want to crop an image in VB and to store the cropped image in another image box or any... I want source code samples
2
by: sampath nslabs | last post by:
sir How to crop the image in visual basic 6.0.iam geting in vb.net but i want purelly in vb.plese give the code for that or give me useful snippts.i expecting source code for crop the image .pls...
0
by: brahimbb17 | last post by:
There is no foolproof way to always win when gambling http://crop-finder-for-travian.blogspot.com . That is why it’s called gambling, you take risks and reap the benefits when lady lucks sides by...
3
by: fuchsia555 | last post by:
hi is there a code to crop bottom border from an image when creating thumbnail for this image without crop the original image , but just crop 15px bottom border for creating the thumbnails for the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.