image editing
|colorizing
Colorizing
Colorizing images is fairly easy to do. The easiest way to colorize an image is fairly simple to grasp. Create an image of the same dimensions and fill that image with the color you want to change it to. This new image is then placed on top of the older image, giving it a colorized look.
full source of colorizing [ line 1 - 30 ] | download colorizing
| 1 | <?php |
| 2 | function imagecolorize (& $im ,& $col ,$pct ) |
| 3 | { |
| 4 | // Get the image's width |
| 5 | $im_w = imagesx ($im ); |
| 6 | // Get the image's height |
| 7 | $im_h = imagesy ($im ); |
| 8 | // Set a pixel with the color, so we can get it easily |
| 9 | $setpixel = imagesetpixel ($im ,$im_w ,0,$col ); |
| 10 | // Get the color |
| 11 | $index = imagecolorat ($im ,$im_w ,0); |
| 12 | // Find the color in the index |
| 13 | $rgb = imagecolorsforindex ($im ,$index ); |
| 14 | // Get the red value |
| 15 | $r = $rgb ["red" ]; |
| 16 | // Get the green value |
| 17 | $g = $rgb ["green" ]; |
| 18 | // Get the blue value |
| 19 | $b = $rgb ["blue" ]; |
| 20 | // Create the layover |
| 21 | $layover = imagecreate ($im_w ,$im_h ); |
| 22 | // Allocate the color on this image |
| 23 | $color = imagecolorallocate ($layover ,$r ,$g ,$b ); |
| 24 | // Fill the image with the new color (this really isn't needed) |
| 25 | $fill = imagefill ($layover ,0,0,$color ); |
| 26 | // Merge the layover on top of the older image |
| 27 | $merge = imagecopymerge ($im ,$layover ,0,0,0,0,$im_w ,$im_h ,$pct ); |
| 28 | imagedestroy ($layover ); // Destroy the layover |
| 29 | } |
| 30 | ?> |
36 hits by 13 users in the last 30 minutes.