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


PHP Image::pickColor方法代码示例

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


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

示例1: getAveragePixelColor

 /**
  * @return string
  */
 public function getAveragePixelColor()
 {
     $this->intervention->resize(1, 1);
     $color = substr($this->intervention->pickColor(0, 0, 'hex'), 1);
     $this->intervention->reset();
     return $color;
 }
开发者ID:tippingcanoe,项目名称:imager,代码行数:10,代码来源:ImageData.php

示例2: execute

 /**
  * Calculates checksum of given image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $colors = array();
     $size = $image->getSize();
     for ($x = 0; $x <= $size->width - 1; $x++) {
         for ($y = 0; $y <= $size->height - 1; $y++) {
             $colors[] = $image->pickColor($x, $y, 'array');
         }
     }
     $this->setOutput(md5(serialize($colors)));
     return true;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:18,代码来源:ChecksumCommand.php

示例3: execute

 /**
  * Applies an alpha mask to an image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $mask_source = $this->argument(0)->value();
     $mask_w_alpha = $this->argument(1)->type('bool')->value(false);
     $image_size = $image->getSize();
     // create empty canvas
     $canvas = $image->getDriver()->newImage($image_size->width, $image_size->height, array(0, 0, 0, 0));
     // build mask image from source
     $mask = $image->getDriver()->init($mask_source);
     $mask_size = $mask->getSize();
     // resize mask to size of current image (if necessary)
     if ($mask_size != $image_size) {
         $mask->resize($image_size->width, $image_size->height);
     }
     imagealphablending($canvas->getCore(), false);
     if (!$mask_w_alpha) {
         // mask from greyscale image
         imagefilter($mask->getCore(), IMG_FILTER_GRAYSCALE);
     }
     // redraw old image pixel by pixel considering alpha map
     for ($x = 0; $x < $image_size->width; $x++) {
         for ($y = 0; $y < $image_size->height; $y++) {
             $color = $image->pickColor($x, $y, 'array');
             $alpha = $mask->pickColor($x, $y, 'array');
             if ($mask_w_alpha) {
                 $alpha = $alpha[3];
                 // use alpha channel as mask
             } else {
                 if ($alpha[3] == 0) {
                     // transparent as black
                     $alpha = 0;
                 } else {
                     // $alpha = floatval(round((($alpha[0] + $alpha[1] + $alpha[3]) / 3) / 255, 2));
                     // image is greyscale, so channel doesn't matter (use red channel)
                     $alpha = floatval(round($alpha[0] / 255, 2));
                 }
             }
             // preserve alpha of original image...
             if ($color[3] < $alpha) {
                 $alpha = $color[3];
             }
             // replace alpha value
             $color[3] = $alpha;
             // redraw pixel
             $canvas->pixel($color, $x, $y);
         }
     }
     // replace current image with masked instance
     $image->setCore($canvas->getCore());
     return true;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:57,代码来源:MaskCommand.php

示例4: execute

 /**
  * Trims away parts of an image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $base = $this->argument(0)->type('string')->value();
     $away = $this->argument(1)->value();
     $tolerance = $this->argument(2)->type('numeric')->value(0);
     $feather = $this->argument(3)->type('numeric')->value(0);
     $width = $image->getWidth();
     $height = $image->getHeight();
     // default values
     $checkTransparency = false;
     // define borders to trim away
     if (is_null($away)) {
         $away = array('top', 'right', 'bottom', 'left');
     } elseif (is_string($away)) {
         $away = array($away);
     }
     // lower border names
     foreach ($away as $key => $value) {
         $away[$key] = strtolower($value);
     }
     // define base color position
     switch (strtolower($base)) {
         case 'transparent':
         case 'trans':
             $checkTransparency = true;
             $base_x = 0;
             $base_y = 0;
             break;
         case 'bottom-right':
         case 'right-bottom':
             $base_x = $width - 1;
             $base_y = $height - 1;
             break;
         default:
         case 'top-left':
         case 'left-top':
             $base_x = 0;
             $base_y = 0;
             break;
     }
     // pick base color
     if ($checkTransparency) {
         $color = new Color();
         // color will only be used to compare alpha channel
     } else {
         $color = $image->pickColor($base_x, $base_y, 'object');
     }
     $top_x = 0;
     $top_y = 0;
     $bottom_x = $width;
     $bottom_y = $height;
     // search upper part of image for colors to trim away
     if (in_array('top', $away)) {
         for ($y = 0; $y < ceil($height / 2); $y++) {
             for ($x = 0; $x < $width; $x++) {
                 $checkColor = $image->pickColor($x, $y, 'object');
                 if ($checkTransparency) {
                     $checkColor->r = $color->r;
                     $checkColor->g = $color->g;
                     $checkColor->b = $color->b;
                 }
                 if ($color->differs($checkColor, $tolerance)) {
                     $top_y = max(0, $y - $feather);
                     break 2;
                 }
             }
         }
     }
     // search left part of image for colors to trim away
     if (in_array('left', $away)) {
         for ($x = 0; $x < ceil($width / 2); $x++) {
             for ($y = $top_y; $y < $height; $y++) {
                 $checkColor = $image->pickColor($x, $y, 'object');
                 if ($checkTransparency) {
                     $checkColor->r = $color->r;
                     $checkColor->g = $color->g;
                     $checkColor->b = $color->b;
                 }
                 if ($color->differs($checkColor, $tolerance)) {
                     $top_x = max(0, $x - $feather);
                     break 2;
                 }
             }
         }
     }
     // search lower part of image for colors to trim away
     if (in_array('bottom', $away)) {
         for ($y = $height - 1; $y >= floor($height / 2) - 1; $y--) {
             for ($x = $top_x; $x < $width; $x++) {
                 $checkColor = $image->pickColor($x, $y, 'object');
                 if ($checkTransparency) {
                     $checkColor->r = $color->r;
                     $checkColor->g = $color->g;
                     $checkColor->b = $color->b;
//.........这里部分代码省略.........
开发者ID:Roc4rdho,项目名称:app,代码行数:101,代码来源:TrimCommand.php

示例5: testBackupKeepTransparency

 public function testBackupKeepTransparency($value = '')
 {
     $img = new Image('public/circle.png');
     $img->backup();
     $img->reset();
     $transparent = array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0.0);
     $this->assertEquals($transparent, $img->pickColor(0, 0, 'array'));
 }
开发者ID:Vrian7ipx,项目名称:repocas,代码行数:8,代码来源:ImageTest.php

示例6: pickColor

 /**
  * Picks and formats color at position
  *
  * @param int $x
  * @param int $y
  * @param string $format
  * @return mixed 
  * @static 
  */
 public static function pickColor($x, $y, $format = null)
 {
     return \Intervention\Image\Image::pickColor($x, $y, $format);
 }
开发者ID:jorzhikgit,项目名称:MLM-Nexus,代码行数:13,代码来源:_ide_helper.php

示例7: execute

 /**
  * Trims away parts of an image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $base = $this->argument(0)->type('string')->value();
     $away = $this->argument(1)->value();
     $tolerance = $this->argument(2)->type('numeric')->value(0);
     $feather = $this->argument(3)->type('numeric')->value(0);
     $width = $image->getWidth();
     $height = $image->getHeight();
     $checkTransparency = false;
     // define borders to trim away
     if (is_null($away)) {
         $away = array('top', 'right', 'bottom', 'left');
     } elseif (is_string($away)) {
         $away = array($away);
     }
     // lower border names
     foreach ($away as $key => $value) {
         $away[$key] = strtolower($value);
     }
     // define base color position
     switch (strtolower($base)) {
         case 'transparent':
         case 'trans':
             $checkTransparency = true;
             $base_x = 0;
             $base_y = 0;
             break;
         case 'bottom-right':
         case 'right-bottom':
             $base_x = $width - 1;
             $base_y = $height - 1;
             break;
         default:
         case 'top-left':
         case 'left-top':
             $base_x = 0;
             $base_y = 0;
             break;
     }
     // pick base color
     if ($checkTransparency) {
         $base_color = new Color();
         // color will only be used to compare alpha channel
     } else {
         $base_color = $image->pickColor($base_x, $base_y, 'object');
     }
     // trim on clone to get only coordinates
     $trimed = clone $image->getCore();
     // add border to trim specific color
     $trimed->borderImage($base_color->getPixel(), 1, 1);
     // trim image
     $trimed->trimImage(65850 / 100 * $tolerance);
     // get coordinates of trim
     $imagePage = $trimed->getImagePage();
     list($crop_x, $crop_y) = array($imagePage['x'] - 1, $imagePage['y'] - 1);
     // $trimed->setImagePage(0, 0, 0, 0);
     list($crop_width, $crop_height) = array($trimed->width, $trimed->height);
     // adjust settings if right should not be trimed
     if (!in_array('right', $away)) {
         $crop_width = $crop_width + ($width - ($width - $crop_x));
     }
     // adjust settings if bottom should not be trimed
     if (!in_array('bottom', $away)) {
         $crop_height = $crop_height + ($height - ($height - $crop_y));
     }
     // adjust settings if left should not be trimed
     if (!in_array('left', $away)) {
         $crop_width = $crop_width + $crop_x;
         $crop_x = 0;
     }
     // adjust settings if top should not be trimed
     if (!in_array('top', $away)) {
         $crop_height = $crop_height + $crop_y;
         $crop_y = 0;
     }
     // add feather
     $crop_width = min($width, $crop_width + $feather * 2);
     $crop_height = min($height, $crop_height + $feather * 2);
     $crop_x = max(0, $crop_x - $feather);
     $crop_y = max(0, $crop_y - $feather);
     // finally crop based on page
     $image->getCore()->cropImage($crop_width, $crop_height, $crop_x, $crop_y);
     $image->getCore()->setImagePage(0, 0, 0, 0);
     $trimed->destroy();
     return true;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:92,代码来源:TrimCommand.php

示例8: testInsertPng8WithAlphaChannel

 public function testInsertPng8WithAlphaChannel()
 {
     $img = new Image(null, 16, 16, '#ff0000');
     $img->insert('public/png8.png');
     $this->assertEquals('#ff0000', $img->pickColor(0, 0, 'hex'));
     $this->assertEquals('#8c8c8c', $img->pickColor(10, 10, 'hex'));
 }
开发者ID:rosskmurphy,项目名称:Laravel-4-login-registration,代码行数:7,代码来源:ImageTest.php

示例9: testBackup

 public function testBackup()
 {
     $img = new Image(null, 800, 600, '#0000ff');
     $img->fill('#00ff00');
     $img->backup();
     $img->resize(200, 200);
     $img->reset();
     $this->assertInternalType('int', $img->width);
     $this->assertInternalType('int', $img->height);
     $this->assertEquals($img->width, 800);
     $this->assertEquals($img->height, 600);
     $this->assertEquals('#00ff00', $img->pickColor(0, 0, 'hex'));
     $img = new Image('public/tile.png');
     $img->resize(10, 10);
     $img->fill('#00ff00');
     $img->backup();
     $img->resize(5, 5);
     $img->reset();
     $this->assertInternalType('int', $img->width);
     $this->assertInternalType('int', $img->height);
     $this->assertEquals($img->width, 10);
     $this->assertEquals($img->height, 10);
     $this->assertEquals('#00ff00', $img->pickColor(0, 0, 'hex'));
 }
开发者ID:andrewpurkett,项目名称:demo-dropbox-rest-service,代码行数:24,代码来源:ImageTest.php


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