本文整理汇总了PHP中imagecopymergegray函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecopymergegray函数的具体用法?PHP imagecopymergegray怎么用?PHP imagecopymergegray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecopymergegray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hashImage
public static function hashImage($res, $size = 8)
{
$res = imagecreatefromstring(file_get_contents($res));
// make sure this is a resource
$rescached = imagecreatetruecolor($size, $size);
imagecopyresampled($rescached, $res, 0, 0, 0, 0, $size, $size, imagesx($res), imagesy($res));
imagecopymergegray($rescached, $res, 0, 0, 0, 0, $size, $size, 50);
$w = imagesx($rescached);
$h = imagesy($rescached);
$pixels = array();
for ($y = 0; $y < $size; $y++) {
for ($x = 0; $x < $size; $x++) {
$rgb = imagecolorsforindex($rescached, imagecolorat($rescached, $x, $y));
$r = $rgb['red'];
$g = $rgb['green'];
$b = $rgb['blue'];
$gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
$gs = floor($gs);
$pixels[] = $gs;
}
}
// find the average value in the array
$avg = self::arrayAverage($pixels);
// create a hash (1 for pixels above the mean, 0 for average or below)
$index = 0;
foreach ($pixels as $px) {
$hash[$index] = $px > $avg;
$index += 1;
}
return $hash;
}
示例2: make_grayscale
public function make_grayscale()
{
// create a copy
$dest = $this->image;
unset($this->image);
$this->load();
if (is_resource($dest)) {
// Apply grayscale filter
imagecopymergegray($dest, $this->image, 0, 0, 0, 0, $this->size['width'], $this->size['height'], 0);
imagegammacorrect($dest, 1.0, apply_filters('grayscale_gamma_correction', 0.7));
imagedestroy($this->image);
$this->image = $dest;
return true;
}
}
示例3: waterMark
function waterMark($source, $logo, $alpha = 50, $isstream = false)
{
list($swidth, $sheight) = getimagesize($source);
list($width, $height) = getimagesize($logo);
$fl =& $this->bd->make('fl');
$ext = $fl->getFileExtName($source, false);
$ext2 = $fl->getFileExtName($logo, false);
$s_pic = $this->createImage($source, $ext);
imagealphablending($s_pic, true);
$l_pic = $this->createImage($logo, $ext2);
imagecopymergegray($s_pic, $l_pic, intval($swidth - $width), intval($sheight - $height), 0, 0, $width, $height, $alpha);
if ($this->writeImage($s_pic, $source, 100, $ext)) {
return true;
} else {
return false;
}
}
示例4: apply
public function apply($resource)
{
// Extract arguments
@(list(, $image, $method, $x1, $y1, $x2, $y2, $src_w, $src_h, $pct) = func_get_args());
$x1 = (int) $x1;
$y1 = (int) $y1;
$x2 = (int) $x2;
$y2 = (int) $y2;
$src_w = (int) $src_w;
$src_h = (int) $src_h;
$pct = (int) $pct;
// Verify
if ($image instanceof Imagix\AbstractImage) {
$image = $image->getResource();
} elseif (!is_resource($image)) {
throw new Exception("The 'image' parameter must be a valid GD resource or a Lumy\\Image\\AbstractImage child object");
}
// Normalize
if (!$src_w) {
$src_w = imagesx($image);
}
if (!$src_h) {
$src_h = imagesy($image);
}
if ($pct === null) {
$pct = 50;
} elseif ($pct < 0) {
$pct = 0;
} elseif ($pct > 100) {
$pct = 100;
}
// Merge images
switch ($method) {
case self::GRAYSCALE:
imagecopymergegray($resource, $image, $x1, $y1, $x2, $y2, $src_w, $src_h, $pct);
break;
case self::NORMAL:
default:
imagecopymerge($resource, $image, $x1, $y1, $x2, $y2, $src_w, $src_h, $pct);
}
return $resource;
}
示例5: Thaiza
function Thaiza($Header, $Birth_Date, $Image_1, $Image_2)
{
$Now = date("j F Y");
$Total_Day = datediff('d', $Now, $Birth_Date, false);
if ($Total_Day <= 0) {
$Week = 0;
$Day = 0;
} else {
$Week = floor($Total_Day / 7);
$Day = $Total_Day % 7;
}
$px_w = (40 - $Week) * 10;
if ($px_w >= 360) {
$px_w = 360;
}
if ($px_w <= 40) {
$px_w = 40;
}
$String_2 = "{$Week} weeks and {$Day} days pregnant. Only {$Total_Day} days to go.";
$image_1 = imagecreate(400, 100);
$background_color = imagecolorallocate($image_1, 255, 255, 255);
$image_2 = imagecreatefromjpeg($Image_1);
$image_3 = imagecreatefromjpeg($Image_2);
imagecopy($image_1, $image_2, 0, 20, 0, 0, 400, 60);
imagecopymergegray($image_1, $image_3, $px_w, 20, 0, 0, 40, 60, 70);
$Color = imagecolorallocate($image_1, 0, 0, 0);
$px_1 = (imagesx($image_1) - 7.5 * strlen($Header)) / 2;
$py_1 = imagesy($image_1) - 90;
imagestring($image_1, 3, $px_1, $py_1, $Header, $Color);
$px_2 = (imagesx($image_1) - 7.5 * strlen($String_2)) / 2;
$py_2 = imagesy($image_1) - 20;
imagestring($image_1, 3, $px_2, $py_2, $String_2, $Color);
Header("Content-type: image/jpeg");
imagepng($image_1);
imagedestroy($image_1);
}
示例6: copy
static function copy(&$image, $picture, $param, $mode = 5)
{
switch ($mode) {
case 1:
//拷贝
return imagecopy($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5]);
case 2:
//拷贝+合并
return imagecopymerge($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6]);
case 3:
//灰度拷贝+合并
return imagecopymergegray($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6]);
case 4:
//拷贝+调整大小
return imagecopyresized($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6], $param[7]);
case 5:
//采样+拷贝+调整大小
//采样+拷贝+调整大小
default:
return imagecopyresampled($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6], $param[7]);
}
}
示例7: gray
/**
* add grayscale effect for given gd resource<br/>
* <b>Note :</b>
* gray method work with imagefilter function or imagecopymergegray if exist but if not
* it will also work but it will take more time
* @param resource $virtual_image gd resource
* @return boolean true on success false otherwise
*/
public static function gray($virtual_image)
{
if (@get_resource_type($virtual_image) != TIP_RT) {
self::logger("gray", " Not A GD Resource");
return false;
}
$is_exist = function_exists('imagefilter');
if ($is_exist == true) {
self::activateAlphaChannel($virtual_image);
return @imagefilter($virtual_image, IMG_FILTER_GRAYSCALE);
} else {
self::activateAlphaChannel($virtual_image);
$width = self::getWidth($virtual_image);
$height = self::getHeight($virtual_image);
$result = @imagecopymergegray($virtual_image, $virtual_image, 0, 0, 0, 0, $width, $height, 0);
if ($result) {
return true;
}
self::logger("gray", "GD Lib Does Not Support Gray Advanced Method Running Slow Mode", TULIP_NOTICE);
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$color_index = @imagecolorat($virtual_image, $x, $y);
$rgb = @imagecolorsforindex($virtual_image, $color_index);
$fixed_rgb = @round(($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3);
$new_color = @imagecolorallocate($virtual_image, $fixed_rgb, $fixed_rgb, $fixed_rgb);
if (!@imagesetpixel($virtual_image, $x, $y, $new_color)) {
self::logger("gray", "Error Setting Pixels");
return false;
}
}
}
return true;
}
}
示例8: copy
static function copy($res, $res_img, $mode, $arr)
{
if ($mode == 1) {
//拷贝
return imagecopy($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5]);
}
if ($mode == 2) {
//拷贝+合并
return imagecopymerge($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6]);
}
if ($mode == 3) {
//灰度拷贝+合并
return imagecopymergegray($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6]);
}
if ($mode == 4) {
//拷贝+调整大小
return imagecopyresized($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], $arr[7]);
}
if ($mode == 5) {
//采样+拷贝+调整大小
return imagecopyresampled($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], $arr[7]);
}
}
示例9: HashImage
public function HashImage($res, $rot = 0, $mir = 0, $size = 8, $WhichHash = 'aHash')
{
$res = $this->NormalizeAsResource($res);
// make sure this is a resource
$rescached = imagecreatetruecolor($size, $size);
imagecopyresampled($rescached, $res, 0, 0, 0, 0, $size, $size, imagesx($res), imagesy($res));
imagecopymergegray($rescached, $res, 0, 0, 0, 0, $size, $size, 50);
$w = imagesx($rescached);
$h = imagesy($rescached);
$pixels = array();
for ($y = 0; $y < $size; $y++) {
for ($x = 0; $x < $size; $x++) {
/* instead of rotating the image, we'll rotate the position of the pixels to allow us to generate a hash
we can use to judge if one image is a rotated or flipped version of the other, without actually creating
an extra image resource. This currently only works at all for 90 degree rotations and mirrors. */
switch ($rot) {
case 90:
$rx = $h - 1 - $y;
$ry = $x;
break;
case 180:
$rx = $w - $x - 1;
$ry = $h - 1 - $y;
break;
case 270:
$rx = $y;
$ry = $h - $x - 1;
break;
default:
$rx = $x;
$ry = $y;
}
switch ($mir) {
case 1:
$rx = $w - $rx - 1;
break;
case 2:
$ry = $h - $ry;
break;
case 3:
$rx = $w - $rx - 1;
$ry = $h - $ry;
break;
default:
break;
}
$rgb = imagecolorsforindex($rescached, imagecolorat($rescached, $rx, $ry));
$r = $rgb['red'];
$g = $rgb['green'];
$b = $rgb['blue'];
$gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
$gs = floor($gs);
$pixels[] = $gs;
//$index++;
}
}
// find the average value in the array
$avg = $this->ArrayAverage($pixels);
// create a hash (1 for pixels above the mean, 0 for average or below)
$index = 0;
// Legendante - Added a check to use one of two hashes
// Use the difference hash (dHash) as per Dr. Neal Krawetz
// http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
if ($WhichHash == 'dHash') {
foreach ($pixels as $ind => $px) {
// Legendante - Uses the original 8*8 comparison originally suggested to Dr. Krawetz
// not the modified 9*8 as suggested by Dr. Krawetz
if (!isset($pixels[$ind + 1])) {
$ind = -1;
}
if ($px > $pixels[$ind + 1]) {
$hash[] = 1;
} else {
$hash[] = 0;
}
}
} else {
foreach ($pixels as $px) {
if ($px > $avg) {
$hash[$index] = 1;
} else {
$hash[$index] = 0;
}
$index += 1;
}
}
// return the array
return $hash;
}
示例10: grayscale
public function grayscale()
{
//$newImage=$this->createImage($this->_width, $this->_height, $this->trueColor);
$newImage = imagecreatetruecolor($this->_width, $this->_height);
imagecopy($newImage, $this->_image, 0, 0, 0, 0, $this->_width, $this->_height);
imagecopymergegray($newImage, $newImage, 0, 0, 0, 0, $this->_width, $this->_height, 0);
imagedestroy($this->_image);
$this->_image = $newImage;
return $this;
}
示例11: convert_theme
function convert_theme($in_name, $out_name, $ws, $hs)
{
global $message;
// debug
// echo '--- THEME resize called : ' . $in_name . ' - ' . $out_name . ' - ' . $ws . 'x' . $hs ;
$image_info = getimagesize($in_name);
// get source image width/height
//
$sw = $image_info[0];
$sh = $image_info[1];
$parts = pathinfo($out_name);
$file_ext = strtolower($parts['extension']);
// $file_name = $parts['filename'];
$base_name = $parts['basename'];
$pos = strrpos($base_name, ".");
$file_name = substr($base_name, 0, $pos);
$file_path = $parts['dirname'];
// create & load original image
//
$img = false;
if ($file_ext == 'jpg' or $file_ext == 'jpeg') {
$img = imagecreatefromjpeg($in_name);
} else {
if ($file_ext == 'gif') {
$img = imagecreatefromgif($in_name);
} else {
if ($file_ext == 'png') {
$img = imagecreatefrompng($in_name);
}
}
}
if ($img == false) {
$message = "Cannot load image";
return -5;
}
//
$dw = $ws[0];
$dh = $hs[0];
$out_img = imagecreatetruecolor($dw, $dh);
imagecopyresized($out_img, $img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
$out_file = $file_path . '/' . $file_name . '_big.' . $file_ext;
$ret = save_image_by_type($out_img, $out_file, $file_ext);
if ($ret == false) {
$message = "Cannot write image";
return -3;
}
//
// icon
//
$dw = $ws[1];
$dh = $hs[1];
imageDestroy($out_img);
$out_img = imagecreatetruecolor($dw, $dh);
imagecopyresized($out_img, $img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
$out_file = $file_path . '/' . $file_name . '_yes.' . $file_ext;
$ret = save_image_by_type($out_img, $out_file, $file_ext);
if ($ret == false) {
$message = "Cannot write image";
return -3;
}
$out_file = $file_path . '/' . $file_name . '_off.' . $file_ext;
$gray_img = imagecreatetruecolor($dw, $dh);
imagecopymergegray($gray_img, $out_img, 0, 0, 0, 0, $dw, $dh, 60);
$ret = save_image_by_type($gray_img, $out_file, $file_ext);
if ($ret == false) {
$message = "Cannot write image";
return -3;
}
imageDestroy($gray_img);
$out_file = $file_path . '/' . $file_name . '_on.' . $file_ext;
$ret = save_image_by_type($out_img, $out_file, $file_ext);
if ($ret == false) {
$message = "Cannot write image";
return -3;
}
$out_file = $file_path . '/' . $file_name . '_ov.' . $file_ext;
$ret = save_image_by_type($out_img, $out_file, $file_ext);
if ($ret == false) {
$message = "Cannot write image";
return -3;
}
// wap icon
//
$dw = $ws[2];
$dh = $hs[2];
imageDestroy($out_img);
$out_img = imagecreatetruecolor($dw, $dh);
imagecopyresized($out_img, $img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
$ret = imagetruecolortopalette($out_img, true, 255);
// image, dither, ncolors
$out_file = $file_path . '/' . $file_name . '_wap.png';
$ret = imagepng($out_img, $out_file, $file_ext);
chmod($out_file, 0755);
if ($ret == false) {
$message = "Cannot write image";
return -3;
}
imageDestroy($out_img);
imageDestroy($img);
return 0;
//.........这里部分代码省略.........
示例12: mixGray
public function mixGray($source, array $settings) : InternalGD
{
if (!is_resource($source)) {
throw new InvalidArgumentException('Error', 'resourceParameter', '1.($source)');
}
$xt = isset($settings['xt']) ? $settings['xt'] : 0;
$yt = isset($settings['yt']) ? $settings['yt'] : 0;
$xs = isset($settings['xs']) ? $settings['xs'] : 0;
$ys = isset($settings['ys']) ? $settings['ys'] : 0;
$width = isset($settings['width']) ? $settings['width'] : 0;
$height = isset($settings['height']) ? $settings['height'] : 0;
$percent = isset($settings['percent']) ? $settings['percent'] : 0;
imagecopymergegray($this->canvas, $source, $xt, $yt, $xs, $ys, $width, $height, $percent);
return $this;
}
示例13: greyscale
/**
* Converts the image to greyscale
*
* @return bool|PEAR_Error TRUE or a PEAR_Error object on error
* @access public
*/
function greyscale()
{
imagecopymergegray($this->imageHandle, $this->imageHandle, 0, 0, 0, 0, $this->new_x, $this->new_y, 0);
return true;
}
示例14: define
<?php
define("SRC_FILE", "php.png");
$img = imagecreatefrompng(SRC_FILE);
$img_copy = imagecreatefrompng(SRC_FILE);
imagecopymergegray($img_copy, $img, 10, 10, 0, 0, imagesx($img), imagesy($img), 50);
header("Content-Type: image/png");
imagepng($img_copy);
示例15: watermarkImage
/**
* 给源图片打上图片水印
* (貌似有些打出来达不到想要的效果)
* 水印图片如果是 png 的话,貌似全透明的效果出不来
* 如果源图是png8貌似打出来效果不好
* @see Lib_Image_Abstract::watermarkImage()
* @param string $watermarkPath 水印图片的绝对路径
* @param string $place 打水印的位置(position);取值见常量。默认southeast:右下角;center:中间;southwest:左下角;northeast:右上角; northwest:左上角
* @param integer $x 打水印的开始位置,X轴;如果传入了$place,此值将做为偏移量
* @param integer $y 打水印的开始位置,Y轴;如果传入了$place,此值将做为偏移量
* @param integer $alpha 水印图片的透明度,取值0(全透明)-100(不透明);仅对 jpg 格式的水印图片有效(暂不支持)
* @param integer $angle TODO 水印图片的旋转角度
* @return boolean
*/
public function watermarkImage($watermarkPath, $place = 'southeast', $x = 18, $y = 18, $alpha = 52, $angle = 0)
{
if (!is_file($watermarkPath)) {
$this->_error = '水印图片不存在!';
$this->_im = null;
return false;
}
if (!$this->_isExistIm()) {
return false;
}
$watermarkExt = strtolower(strrchr($watermarkPath, '.'));
if (!in_array($watermarkExt, $this->_allowExt)) {
// 仅通过后缀名进行判断和创建图像资源; TODO 真实的文件类型
$this->_error = '水印图片文件类型不符,只支持 ' . implode('、', $this->_allowExt) . ' 格式的图片';
$this->_im = null;
return false;
}
$watermarkType = substr($watermarkExt, 1);
if ($watermarkType == 'jpg') {
$watermarkType = 'jpeg';
}
$imageFunction = 'imagecreatefrom' . $watermarkType;
$watermarkImg = $imageFunction($watermarkPath);
$watermarkW = imagesx($watermarkImg);
$watermarkH = imagesy($watermarkImg);
if ($this->_sourceWidth < $watermarkW || $this->_sourceHeight < $watermarkH) {
// 多于判断,有时候没有必要考虑
$this->setError('源图片的宽或高小于水印图片的宽或高,无法生成水印图!');
$this->_im = null;
return false;
}
switch ($place) {
case self::PLACE_NORTHWEST:
break;
case self::PLACE_NORTHEAST:
$x = $this->_sourceWidth - ($watermarkW + $x);
break;
case self::PLACE_CENTER:
$x = ($this->_sourceWidth - $watermarkW) / 2;
$y = ($this->_sourceHeight - $watermarkH) / 2;
break;
case self::PLACE_SOUTHWEST:
$y = $this->_sourceHeight - ($watermarkH + $y);
break;
case self::PLACE_SOUTHEAST:
$x = $this->_sourceWidth - ($watermarkW + $x);
$y = $this->_sourceHeight - ($watermarkH + $y);
break;
default:
break;
}
imagealphablending($this->_im, true);
// 设定图像的混色模式; 貌似这里没有什么用,用不用都一样
$boolean = imagecopymergegray($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH, $alpha);
// ubuntu 64 位下测试不行; ubuntu 32 位下测试可以
// 用灰度拷贝并合并图像的一部分;拷贝水印到目标文件
//$boolean = imagecopy($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH); // ubuntu 64 位下测试还可以
//$boolean = imagecopymerge($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH, 100); // ubuntu 64 位下测试不行
//$boolean = imagecopyresized($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH, $watermarkW, $watermarkH); // ubuntu 64 位下测试还可以
//$boolean = imagecopyresampled($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH, $watermarkW, $watermarkH); // ubuntu 64 位下测试还可以
// int imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h); 拷贝图像的一部分
//imagecopyresized($this->_im, $watermarkImg, $start['x'], $start['y'], 0, 0, $watermarkW, $watermarkH, $watermarkW, $watermarkH); // 这个写法就和上面的一模一样
//int imagecopymerge ( 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_x,src_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_x 和 dst_y 的位置上。两图像将根据 pct 来决定合并程度,其值范围从 0 到 100。
// 当 pct = 0 时,实际上什么也没做 当为 100 时本函数和 imagecopy() 完全一样。
// imagecopymergegray 和 imagecopymerge() 完全一样只除了合并时通过在拷贝操作前将目标像素转换为灰度级来保留了原色度。
if ($boolean) {
return true;
} else {
$this->_error = '拷贝并合并图像时出错';
$this->_im = null;
return false;
}
}