I want to crop a rectangular image into a non-rectangular shape. I understand that if you take it literally, it is impossible. I want the result to be an image X, cropped to shape Y, on a transparent background.
Say, for example, that I want to photograph the Idaho flag and crop it to the state of Idaho. I assume I will do something like this:
- Create an image with opaque pixels for an Idaho shape, transparent pixels everywhere.
- Read and save a bitmap of this Idaho image
- For each opaque pixel location in the Idaho state image, copy the corresponding pixel from the Idaho state flag image and place it on a blank transparent canvas.
Step 1 will obviously be done manually, but the rest will be done programmatically. I think I have the right idea in general, but I don’t know how I will approach the specifics. Can someone point me in the right direction?
Regarding the implementation technology, I'm a PHP guy, so using gdLibrary or something that works with PHP will probably be the best way for me.
source
share