Page 1 of 1

how to crop a "Arbitrary" shape from an image

Posted: Fri Jul 07, 2006 10:02 pm
by wasedaxiao
If GD2 library provides functions to be able to do that?

Posted: Wed Jul 12, 2006 12:24 am
by Benjamin
Have you looked at the image functions?

http://www.php.net/manual/en/ref.image.php

Posted: Thu Jul 13, 2006 11:02 pm
by wasedaxiao
astions wrote:Have you looked at the image functions?

http://www.php.net/manual/en/ref.image.php
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.

thanks.

Posted: Fri Jul 14, 2006 4:06 am
by onion2k
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.
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.

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.

Posted: Fri Jul 14, 2006 4:14 am
by wasedaxiao
onion2k wrote:
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.
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.

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.
Yes, I agree with you. As students, it's better not to use exist APIs for learning.

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.