how to crop a "Arbitrary" shape from an image
Moderators: onion2k, General Moderators
-
wasedaxiao
- Forum Newbie
- Posts: 3
- Joined: Fri Jul 07, 2006 9:55 pm
how to crop a "Arbitrary" shape from an image
If GD2 library provides functions to be able to do that?
-
wasedaxiao
- Forum Newbie
- Posts: 3
- Joined: Fri Jul 07, 2006 9:55 pm
That's the problem with Java in my opinion .. practically everything has been provided so people forget how to write their own code. PHP is pretty bad for it too.wasedaxiao wrote:I have checked the functions, but could not find a way to clip an arbitrary shape(e.g. triangle) out of a photo. It seems that it can only clip rectangle shapes.
In Java, it provides such APIs to do that. So i have to implement this functions by myself?
Any idea, please.
Anyway .. to crop an arbitrary shape you'll need to work out the rectangular bounds of the area you want, copy that rectangle to a temporary canvas, then work out which bits of that rectangle are outside the area you want to keep, and you'll need to set those pixels to transparent. That'll give you a temporary image you can then copy to another image.
-
wasedaxiao
- Forum Newbie
- Posts: 3
- Joined: Fri Jul 07, 2006 9:55 pm
Yes, I agree with you. As students, it's better not to use exist APIs for learning.onion2k wrote:That's the problem with Java in my opinion .. practically everything has been provided so people forget how to write their own code. PHP is pretty bad for it too.wasedaxiao wrote:I have checked the functions, but could not find a way to clip an arbitrary shape(e.g. triangle) out of a photo. It seems that it can only clip rectangle shapes.
In Java, it provides such APIs to do that. So i have to implement this functions by myself?
Any idea, please.
Anyway .. to crop an arbitrary shape you'll need to work out the rectangular bounds of the area you want, copy that rectangle to a temporary canvas, then work out which bits of that rectangle are outside the area you want to keep, and you'll need to set those pixels to transparent. That'll give you a temporary image you can then copy to another image.
It seems that there are not such functions in PHP now and i will try your basic idea.
thanks for your comments. I will post back when i getting the results.