Crop image into polygon shape

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deadfish
Forum Newbie
Posts: 2
Joined: Fri Oct 09, 2009 8:22 am

Crop image into polygon shape

Post by deadfish »

Hi Everyone (this is my first post),

I am trying to figure a way of cropping a polygon out of an image. I have been reading other similar code. It seems that most code is based around the following process:

-Resize the image to fit the width and height of the polygon shape,

Create a blank image of an unusual colour the same size,

Overlay transparent pixels in the shape of the polygon,

Overlay that on to the resized image

set the unusual colour to be transparent...

like http://www.google.co.uk/url?sa=t&source ... WWl8jo3J7g


My problem is I do not want the code to be reliant on the unusual colour not being in the original image. Does anyone have a better method or some code which I can use to check if the unusual colour is in the image.

Thanks in Advance.
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: Crop image into polygon shape

Post by desperado »

why not just use a .png mask as png supports transparency/alpha?
deadfish
Forum Newbie
Posts: 2
Joined: Fri Oct 09, 2009 8:22 am

Re: Crop image into polygon shape

Post by deadfish »

..But what I want is the final image inside the shape to be surrounded by transparency.

So once I have masked it the mask will have a colour which I must then make transparent... but if that colour is in the image then that will be ruined too. So either I am looking for a better way of masking or a way of looking through the image to find a colour not present to use as the mask colour.

Thanks :)
Post Reply