当前位置: 首页>>代码示例>>PHP>>正文


PHP WideImage_Image::getRGBAt方法代码示例

本文整理汇总了PHP中WideImage_Image::getRGBAt方法的典型用法代码示例。如果您正苦于以下问题:PHP WideImage_Image::getRGBAt方法的具体用法?PHP WideImage_Image::getRGBAt怎么用?PHP WideImage_Image::getRGBAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WideImage_Image的用法示例。


在下文中一共展示了WideImage_Image::getRGBAt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * Applies a mask on the copy of source image
  *
  * @param WideImage_Image $image
  * @param WideImage_Image $mask
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @return WideImage_Image
  */
 function execute($image, $mask, $left = 0, $top = 0)
 {
     $left = WideImage_Coordinate::fix($left, $image->getWidth(), $mask->getWidth());
     $top = WideImage_Coordinate::fix($top, $image->getHeight(), $mask->getHeight());
     $width = $image->getWidth();
     $mask_width = $mask->getWidth();
     $height = $image->getHeight();
     $mask_height = $mask->getHeight();
     $result = $image->asTrueColor();
     $result->alphaBlending(false);
     $result->saveAlpha(true);
     $srcTransparentColor = $result->getTransparentColor();
     if ($srcTransparentColor >= 0) {
         # this was here. works without.
         #$trgb = $image->getColorRGB($srcTransparentColor);
         #$trgb['alpha'] = 127;
         #$destTransparentColor = $result->allocateColorAlpha($trgb);
         #$result->setTransparentColor($destTransparentColor);
         $destTransparentColor = $srcTransparentColor;
     } else {
         $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127);
     }
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $mx = $x - $left;
             $my = $y - $top;
             if ($mx >= 0 && $mx < $mask_width && $my >= 0 && $my < $mask_height) {
                 $srcColor = $image->getColorAt($x, $y);
                 if ($srcColor == $srcTransparentColor) {
                     $destColor = $destTransparentColor;
                 } else {
                     $maskRGB = $mask->getRGBAt($mx, $my);
                     if ($maskRGB['red'] == 0) {
                         $destColor = $destTransparentColor;
                     } elseif ($srcColor >= 0) {
                         $imageRGB = $image->getRGBAt($x, $y);
                         $level = $maskRGB['red'] / 255 * (1 - $imageRGB['alpha'] / 127);
                         $imageRGB['alpha'] = 127 - round($level * 127);
                         if ($imageRGB['alpha'] == 127) {
                             $destColor = $destTransparentColor;
                         } else {
                             $destColor = $result->allocateColorAlpha($imageRGB);
                         }
                     } else {
                         $destColor = $destTransparentColor;
                     }
                 }
                 $result->setColorAt($x, $y, $destColor);
             }
         }
     }
     return $result;
 }
开发者ID:NaszvadiG,项目名称:DivaSul,代码行数:62,代码来源:ApplyMask.php

示例2: execute

 /**
  * Applies a mask on the copy of source image
  *
  * @param WideImage_Image $image
  * @param WideImage_Image $mask
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @return WideImage_Image
  */
 function execute($image, $mask, $left = 0, $top = 0)
 {
     $left = WideImage_Coordinate::fix($image->getWidth(), $left);
     $top = WideImage_Coordinate::fix($image->getHeight(), $top);
     $width = $image->getWidth();
     if ($width > $mask->getWidth()) {
         $width = $mask->getWidth();
     }
     $height = $image->getHeight();
     if ($height > $mask->getHeight()) {
         $height = $mask->getHeight();
     }
     $result = $image->asTrueColor();
     $result->alphaBlending(false);
     $result->saveAlpha(true);
     $srcTransparentColor = $image->getTransparentColor();
     if ($srcTransparentColor >= 0) {
         $trgb = $image->getColorRGB($srcTransparentColor);
         $trgb['alpha'] = 127;
         $destTransparentColor = $result->allocateColorAlpha($trgb);
         $result->setTransparentColor($destTransparentColor);
     } else {
         $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127);
     }
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             if ($left + $x < $image->getWidth() && $top + $y < $image->getHeight()) {
                 $srcColor = $image->getColorAt($left + $x, $top + $y);
                 if ($srcColor == $srcTransparentColor) {
                     $destColor = $destTransparentColor;
                 } else {
                     $maskRGB = $mask->getRGBAt($x, $y);
                     if ($maskRGB['red'] == 0) {
                         $destColor = $destTransparentColor;
                     } elseif ($srcColor >= 0) {
                         $imageRGB = $image->getRGBAt($left + $x, $top + $y);
                         $level = $maskRGB['red'] / 255 * (1 - $imageRGB['alpha'] / 127);
                         $imageRGB['alpha'] = 127 - round($level * 127);
                         if ($imageRGB['alpha'] == 127) {
                             $destColor = $destTransparentColor;
                         } else {
                             $destColor = $result->allocateColorAlpha($imageRGB);
                         }
                     } else {
                         $destColor = $destTransparentColor;
                     }
                 }
                 $result->setColorAt($left + $x, $top + $y, $destColor);
             }
         }
     }
     return $result;
 }
开发者ID:eduardosilvapereira,项目名称:mcja,代码行数:62,代码来源:ApplyMask.php

示例3: execute

 /**
  * Returns an image with only specified channels copied
  * 
  * @param WideImage_Image $img
  * @param array $channels
  * @return WideImage_Image
  */
 function execute($img, $channels)
 {
     $blank = array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0);
     $width = $img->getWidth();
     $height = $img->getHeight();
     $copy = WideImage_TrueColorImage::create($width, $height);
     if (count($channels) > 0) {
         for ($x = 0; $x < $width; $x++) {
             for ($y = 0; $y < $height; $y++) {
                 $RGBA = $img->getRGBAt($x, $y);
                 $newRGBA = $blank;
                 foreach ($channels as $channel) {
                     $newRGBA[$channel] = $RGBA[$channel];
                 }
                 $color = $copy->getExactColorAlpha($newRGBA);
                 if ($color == -1) {
                     $color = $copy->allocateColorAlpha($newRGBA);
                 }
                 $copy->setColorAt($x, $y, $color);
             }
         }
     }
     return $copy;
 }
开发者ID:eduardosilvapereira,项目名称:mcja,代码行数:31,代码来源:CopyChannelsTrueColor.php

示例4: execute

 /**
  * Returns sharpened image
  *
  * @param WideImage_Image $image
  * @param float $amount
  * @param int $radius
  * @param float $threshold
  * @return WideImage_Image
  */
 function execute($image, $amount, $radius, $threshold)
 {
     // Attempt to calibrate the parameters to Photoshop:
     if ($amount > 500) {
         $amount = 500;
     }
     $amount = $amount * 0.016;
     if ($radius > 50) {
         $radius = 50;
     }
     $radius = $radius * 2;
     if ($threshold > 255) {
         $threshold = 255;
     }
     $radius = abs(round($radius));
     // Only integers make sense.
     if ($radius == 0) {
         return $image;
     }
     // Gaussian blur matrix
     $matrix = array(array(1, 2, 1), array(2, 4, 2), array(1, 2, 1));
     $blurred = $image->applyConvolution($matrix, 16, 0);
     if ($threshold > 0) {
         // Calculate the difference between the blurred pixels and the original
         // and set the pixels
         for ($x = 0; $x < $image->getWidth(); $x++) {
             for ($y = 0; $y < $image->getHeight(); $y++) {
                 $rgbOrig = $image->getRGBAt($x, $y);
                 $rOrig = $rgbOrig["red"];
                 $gOrig = $rgbOrig["green"];
                 $bOrig = $rgbOrig["blue"];
                 $rgbBlur = $blurred->getRGBAt($x, $y);
                 $rBlur = $rgbBlur["red"];
                 $gBlur = $rgbBlur["green"];
                 $bBlur = $rgbBlur["blue"];
                 // When the masked pixels differ less from the original
                 // than the threshold specifies, they are set to their original value.
                 $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
                 $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
                 $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
                 $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0);
                 if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                     $image->setRGBAt($x, $y, $rgbNew);
                 }
             }
         }
     } else {
         $w = $image->getWidth();
         $h = $image->getHeight();
         for ($x = 0; $x < $w; $x++) {
             for ($y = 0; $y < $h; $y++) {
                 $rgbOrig = $image->getRGBAt($x, $y);
                 $rOrig = $rgbOrig["red"];
                 $gOrig = $rgbOrig["green"];
                 $bOrig = $rgbOrig["blue"];
                 $rgbBlur = $blurred->getRGBAt($x, $y);
                 $rBlur = $rgbBlur["red"];
                 $gBlur = $rgbBlur["green"];
                 $bBlur = $rgbBlur["blue"];
                 $rNew = $amount * ($rOrig - $rBlur) + $rOrig;
                 if ($rNew > 255) {
                     $rNew = 255;
                 } elseif ($rNew < 0) {
                     $rNew = 0;
                 }
                 $gNew = $amount * ($gOrig - $gBlur) + $gOrig;
                 if ($gNew > 255) {
                     $gNew = 255;
                 } elseif ($gNew < 0) {
                     $gNew = 0;
                 }
                 $bNew = $amount * ($bOrig - $bBlur) + $bOrig;
                 if ($bNew > 255) {
                     $bNew = 255;
                 } elseif ($bNew < 0) {
                     $bNew = 0;
                 }
                 $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0);
                 $image->setRGBAt($x, $y, $rgbNew);
             }
         }
     }
     return $image;
 }
开发者ID:ehazell,项目名称:AZDWR,代码行数:93,代码来源:Unsharp.php

示例5: execute

 /**
  * Executes the auto-crop operation on the $img
  * 
  * @param WideImage_Image $img 
  * @param int $rgb_threshold The difference in RGB from $base_color
  * @param int $pixel_cutoff The number of pixels on each border that must be over $rgb_threshold
  * @param int $base_color The color that will get cropped
  * @return WideImage_Image resulting auto-cropped image
  */
 function execute($img, $margin, $rgb_threshold, $pixel_cutoff, $base_color)
 {
     $margin = intval($margin);
     $rgb_threshold = intval($rgb_threshold);
     if ($rgb_threshold < 0) {
         $rgb_threshold = 0;
     }
     $pixel_cutoff = intval($pixel_cutoff);
     if ($pixel_cutoff <= 1) {
         $pixel_cutoff = 1;
     }
     if ($base_color === null) {
         $rgb_base = $img->getRGBAt(0, 0);
     } else {
         if ($base_color < 0) {
             return $img->copy();
         }
         $rgb_base = $img->getColorRGB($base_color);
     }
     $cut_rect = array('left' => 0, 'top' => 0, 'right' => $img->getWidth() - 1, 'bottom' => $img->getHeight() - 1);
     for ($y = 0; $y <= $cut_rect['bottom']; $y++) {
         $count = 0;
         for ($x = 0; $x <= $cut_rect['right']; $x++) {
             $rgb = $img->getRGBAt($x, $y);
             $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']);
             if ($diff > $rgb_threshold) {
                 $count++;
                 if ($count >= $pixel_cutoff) {
                     $cut_rect['top'] = $y;
                     break 2;
                 }
             }
         }
     }
     for ($y = $img->getHeight() - 1; $y >= $cut_rect['top']; $y--) {
         $count = 0;
         for ($x = 0; $x <= $cut_rect['right']; $x++) {
             $rgb = $img->getRGBAt($x, $y);
             $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']);
             if ($diff > $rgb_threshold) {
                 $count++;
                 if ($count >= $pixel_cutoff) {
                     $cut_rect['bottom'] = $y;
                     break 2;
                 }
             }
         }
     }
     for ($x = 0; $x <= $cut_rect['right']; $x++) {
         $count = 0;
         for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) {
             $rgb = $img->getRGBAt($x, $y);
             $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']);
             if ($diff > $rgb_threshold) {
                 $count++;
                 if ($count >= $pixel_cutoff) {
                     $cut_rect['left'] = $x;
                     break 2;
                 }
             }
         }
     }
     for ($x = $cut_rect['right']; $x >= $cut_rect['left']; $x--) {
         $count = 0;
         for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) {
             $rgb = $img->getRGBAt($x, $y);
             $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']);
             if ($diff > $rgb_threshold) {
                 $count++;
                 if ($count >= $pixel_cutoff) {
                     $cut_rect['right'] = $x;
                     break 2;
                 }
             }
         }
     }
     $cut_rect = array('left' => $cut_rect['left'] - $margin, 'top' => $cut_rect['top'] - $margin, 'right' => $cut_rect['right'] + $margin, 'bottom' => $cut_rect['bottom'] + $margin);
     if ($cut_rect['left'] < 0) {
         $cut_rect['left'] = 0;
     }
     if ($cut_rect['top'] < 0) {
         $cut_rect['top'] = 0;
     }
     if ($cut_rect['right'] >= $img->getWidth()) {
         $cut_rect['right'] = $img->getWidth() - 1;
     }
     if ($cut_rect['bottom'] >= $img->getHeight()) {
         $cut_rect['bottom'] = $img->getHeight() - 1;
     }
     return $img->crop($cut_rect['left'], $cut_rect['top'], $cut_rect['right'] - $cut_rect['left'] + 1, $cut_rect['bottom'] - $cut_rect['top'] + 1);
 }
开发者ID:NaszvadiG,项目名称:DivaSul,代码行数:100,代码来源:AutoCrop.php


注:本文中的WideImage_Image::getRGBAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。