超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<imagecopymergeimagecopyresampled>
Last updated: Fri, 22 Jun 2007

imagecopymergegray

(PHP 4 >= 4.0.6, PHP 5)

imagecopymergegray -- 用灰度拷贝并合并图像的一部分

说明

int imagecopymergegray ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct)

src_im 图像中坐标从 src_xsrc_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_xdst_y 的位置上。两图像将根据 pct 来决定合并程度,其值范围从 0 到 100。当 pct = 0 时,实际上什么也没做,当为 100 时本函数和 imagecopy() 完全一样。

本函数和 imagecopymerge() 完全一样只除了合并时通过在拷贝操作前将目标像素转换为灰度级来保留了原色度。

注: 本函数添加于 PHP 4.0.6。




add a note add a note User Contributed Notes
imagecopymergegray
mail at laeubi dot de
09-Oct-2003 03:45
This function don't work properly for me on trucolerimages (have not tried yet for other types) it jsut produce a part-grayscale image, and some color get mesed up.
I found a workaround here:
http://www.phpbuilder.com/columns/cash20030526.php3?page=2

[quote]
Advanced Image Editing Under the GD Library
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.

<?php
function imagecolorize(&$im,&$col,$pct) {
   // Get the image's width
   $im_w = imagesx($im);  
   // Get the image's height
  $im_h = imagesy($im);  
   // Set a pixel with the color, so we can get it easily
   $setpixel = imagesetpixel($im,$im_w,0,$col);  
   // Get the color
   $index = imagecolorat($im,$im_w,0);  
   // Find the color in the index
   $rgb = imagecolorsforindex($im,$index);
   // Get the red value
   $r = $rgb["red"];
   // Get the green value
   $g = $rgb["green"];  
   // Get the blue value
   $b = $rgb["blue"];  
   // Create the layover
   $layover = imagecreate($im_w,$im_h);  
   // Allocate the color on this image
   $color = imagecolorallocate($layover,$r,$g,$b);  
   // Fill the image with the new color (this really isn't needed)
   $fill = imagefill($layover,0,0,$color);  
   // Merge the layover on top of the older image
   $merge = imagecopymerge($im,$layover,0,0,0,0,$im_w,$im_h,$pct);
  imagedestroy($layover); // Destroy the layover
}
?>

If we use a blue layover RGB(0,0,255), we get this result:
[/quote]

if you use black or gray, its not perfekt, but better than nothing ;)

<imagecopymergeimagecopyresampled>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22