當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Imagick::getImagePixelColor方法代碼示例

本文整理匯總了PHP中Imagick::getImagePixelColor方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::getImagePixelColor方法的具體用法?PHP Imagick::getImagePixelColor怎麽用?PHP Imagick::getImagePixelColor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Imagick的用法示例。


在下文中一共展示了Imagick::getImagePixelColor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get_pixel

 public function get_pixel($x, $y)
 {
     $pixel = $this->image->getImagePixelColor($x, $y);
     $color = $pixel->getColor();
     $normalized_color = $pixel->getColor(true);
     return array('color' => ($color['r'] << 16) + ($color['g'] << 8) + $color['b'], 'opacity' => $normalized_color['a']);
 }
開發者ID:anp135,項目名稱:altocms,代碼行數:7,代碼來源:Imagick.php

示例2: getPixel

 public function getPixel($x, $y)
 {
     $pixel = $this->image->getImagePixelColor($x, $y);
     $color = $pixel->getColor();
     $normalizedColor = $pixel->getColor(true);
     $color = ($color['r'] << 16) + ($color['g'] << 8) + $color['b'];
     $opacity = $normalizedColor['a'];
     return $this->buildPixel($x, $y, $color, $opacity);
 }
開發者ID:phpixie,項目名稱:image,代碼行數:9,代碼來源:Resource.php

示例3: assertImageAlphaAtPointImagick

 /**
  * Helper assertion for testing alpha on images using Imagick
  *
  * @param string $image_path
  * @param array $point      array(x,y)
  * @param int $expected
  */
 protected function assertImageAlphaAtPointImagick($image_path, $point, $expected)
 {
     $im = new Imagick($image_path);
     $pixel = $im->getImagePixelColor($point[0], $point[1]);
     $color = $pixel->getColorValue(imagick::COLOR_ALPHA);
     $this->assertEquals($expected, $color);
 }
開發者ID:boonebgorges,項目名稱:develop.wordpress,代碼行數:14,代碼來源:base.php

示例4: getColorAt

 /**
  * {@inheritdoc}
  */
 public function getColorAt(PointInterface $point)
 {
     if (!$point->in($this->getSize())) {
         throw new RuntimeException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight()));
     }
     $pixel = $this->imagick->getImagePixelColor($point->getX(), $point->getY());
     return new Color(array($pixel->getColorValue(\Imagick::COLOR_RED) * 255, $pixel->getColorValue(\Imagick::COLOR_GREEN) * 255, $pixel->getColorValue(\Imagick::COLOR_BLUE) * 255), (int) round($pixel->getColorValue(\Imagick::COLOR_ALPHA) * 100));
 }
開發者ID:rachelleannmorales,項目名稱:aboitiz,代碼行數:11,代碼來源:Image.php

示例5: _getPixel

 protected function _getPixel($x, $y)
 {
     $pixel = $this->im->getImagePixelColor($x, $y);
     $result = array_values($pixel->getColor(true));
     if (!isset($result[3])) {
         $result[3] = 1;
     }
     return $result;
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:9,代碼來源:waImageImagick.class.php

示例6: getAverageLuminosity

 /**
  * @param \Imagick $imagick
  * @return float
  */
 private function getAverageLuminosity(\Imagick $imagick)
 {
     $colors = 0;
     foreach (range(1, self::IMG_SIZE) as $x) {
         foreach (range(1, self::IMG_SIZE) as $y) {
             $rgb = $imagick->getImagePixelColor($x, $y)->getColor();
             $colors += ($rgb['r'] + $rgb['g'] + $rgb['b']) / 3;
         }
     }
     return $colors / self::IMG_SIZE ** 2;
 }
開發者ID:philippecarle,項目名稱:AsciiArt,代碼行數:15,代碼來源:FontAnalyzerCommand.php

示例7: getColorAt

 /**
  * {@inheritdoc}
  */
 public function getColorAt(PointInterface $point)
 {
     if (!$point->in($this->getSize())) {
         throw new RuntimeException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight()));
     }
     try {
         $pixel = $this->imagick->getImagePixelColor($point->getX(), $point->getY());
     } catch (\ImagickException $e) {
         throw new RuntimeException('Error while getting image pixel color', $e->getCode(), $e);
     }
     return $this->pixelToColor($pixel);
 }
開發者ID:scisahaha,項目名稱:generator-craft,代碼行數:15,代碼來源:Image.php

示例8: image

 /**
  * Image caching
  *
  * Resize & cache image into the file system. Returns the template image if product image is not exists
  *
  * @param mixed $name
  * @param int $user_id
  * @param int $width Resizing width
  * @param int $height Resizing height
  * @param bool $watermarked
  * @param bool $overwrite
  * @param bool $best_fit
  * @return string Cached Image URL
  */
 public function image($name, $user_id, $width, $height, $watermarked = false, $overwrite = false, $best_fit = false)
 {
     $storage = DIR_STORAGE . $user_id . DIR_SEPARATOR . $name . '.' . STORAGE_IMAGE_EXTENSION;
     $cache = DIR_IMAGE . 'cache' . DIR_SEPARATOR . $user_id . DIR_SEPARATOR . $name . '-' . (int) $best_fit . '-' . $width . '-' . $height . '.' . STORAGE_IMAGE_EXTENSION;
     $watermark_black = DIR_IMAGE . 'common' . DIR_SEPARATOR . 'watermark-black.png';
     $watermark_white = DIR_IMAGE . 'common' . DIR_SEPARATOR . 'watermark-white.png';
     $cached_url = URL_BASE . 'image' . DIR_SEPARATOR . 'cache' . DIR_SEPARATOR . $user_id . DIR_SEPARATOR . $name . '-' . (int) $best_fit . '-' . $width . '-' . $height . '.' . STORAGE_IMAGE_EXTENSION;
     // Force reset
     if ($overwrite && file_exists($overwrite)) {
         unlink($cache);
     }
     // If image is cached
     if (file_exists($cache)) {
         return $cached_url;
         // If image not cached
     } else {
         // Create directories by path if not exists
         $directories = explode(DIR_SEPARATOR, $cache);
         $path = '';
         foreach ($directories as $directory) {
             $path .= DIR_SEPARATOR . $directory;
             if (!is_dir($path) && false === strpos($directory, '.')) {
                 mkdir($path, 0755);
             }
         }
         // Prepare new image
         $image = new Image($storage);
         $image->resize($width, $height, 1, false, $best_fit);
         if ($watermarked) {
             $average = new Imagick($storage);
             $average->resizeImage(1, 1, Imagick::FILTER_POINT, 0);
             $pixel = $average->getImagePixelColor(1, 1);
             $color = $pixel->getColor();
             $brightness = (0.299 * $color['r'] + 0.587 * $color['g'] + 0.114 * $color['b']) * 100 / 255;
             if ($brightness < 25) {
                 $image->watermark($watermark_white);
             } else {
                 $image->watermark($watermark_black);
             }
         }
         $image->save($cache);
     }
     return $cached_url;
 }
開發者ID:bitsybay,項目名稱:bitsybay,代碼行數:58,代碼來源:cache.php

示例9: hasAlphaChannel

 /**
  * @return bool
  */
 protected function hasAlphaChannel()
 {
     if ($this->isAlphaPossible) {
         $width = $this->resource->getImageWidth();
         // Get the width of the image
         $height = $this->resource->getImageHeight();
         // Get the height of the image
         // We run the image pixel by pixel and as soon as we find a transparent pixel we stop and return true.
         for ($i = 0; $i < $width; $i++) {
             for ($j = 0; $j < $height; $j++) {
                 $pixel = $this->resource->getImagePixelColor($i, $j);
                 $color = $pixel->getColor(true);
                 // get the real alpha not just 1/0
                 if ($color["a"] < 1) {
                     // if there's an alpha pixel, return true
                     return true;
                 }
             }
         }
     }
     // If we dont find any pixel the function will return false.
     return false;
 }
開發者ID:Gerhard13,項目名稱:pimcore,代碼行數:26,代碼來源:Imagick.php

示例10: index

 public function index()
 {
     //exit;
     ini_set("max_execution_time", -1);
     $dir = new DirectoryIterator("swatch");
     foreach ($dir as $fl) {
         if (!$fl->isDot()) {
             if (!$fl->isDir()) {
                 $name = $fl->getFilename();
                 $image = new Imagick('swatch/' . $name);
                 $x = rand(4, 10);
                 $y = rand(4, 10);
                 $pixel = $image->getImagePixelColor($x, $y);
                 $clr = $pixel->getColor();
                 $hex = $this->fromRGB($clr['r'], $clr['g'], $clr['b']);
                 $tn = explode("_", $name);
                 $tn = explode(".", $tn[1]);
                 $tn = $tn[0];
                 rename('swatch/' . $name, 'swatch/' . $tn . "-" . $hex . ".png");
             }
         }
     }
     exit;
 }
開發者ID:ashutoshdev,項目名稱:openrug.com,代碼行數:24,代碼來源:TestController.php

示例11: test_image_preserves_alpha_on_rotate

 /**
  *
  * @ticket 30596
  */
 public function test_image_preserves_alpha_on_rotate()
 {
     $file = DIR_TESTDATA . '/images/transparent.png';
     $pre_rotate_editor = new Imagick($file);
     $pre_rotate_pixel = $pre_rotate_editor->getImagePixelColor(0, 0);
     $pre_rotate_alpha = $pre_rotate_pixel->getColorValue(imagick::COLOR_ALPHA);
     $save_to_file = tempnam(get_temp_dir(), '') . '.png';
     $pre_rotate_editor->writeImage($save_to_file);
     $pre_rotate_editor->destroy();
     $image_editor = new WP_Image_Editor_Imagick($save_to_file);
     $image_editor->load();
     $this->assertNotInstanceOf('WP_Error', $image_editor);
     $image_editor->rotate(180);
     $image_editor->save($save_to_file);
     $this->assertImageAlphaAtPointImagick($save_to_file, array(0, 0), $pre_rotate_alpha);
     unlink($save_to_file);
 }
開發者ID:atimmer,項目名稱:wordpress-develop-mirror,代碼行數:21,代碼來源:editor_imagick.php

示例12: Imagick

<?php

$im = new Imagick("magick:logo");
$im->setImageBackgroundColor("pink");
$im->thumbnailImage(200, 200, true, true);
$color = $im->getImagePixelColor(5, 5);
if ($color->isPixelSimilar("pink", 0)) {
    echo "Similar" . PHP_EOL;
} else {
    var_dump($color->getColorAsString());
}
$color = $im->getImagePixelColor(199, 5);
if ($color->isPixelSimilar("pink", 0)) {
    echo "Similar" . PHP_EOL;
} else {
    var_dump($color->getColorAsString());
}
開發者ID:badlamer,項目名稱:hhvm,代碼行數:17,代碼來源:007_thumbnail_fill.php

示例13: assertImagePixelColor

 /**
  * @Given /^the pixel at coordinate "([^"]*)" should have a color of "#([^"]*)"$/
  */
 public function assertImagePixelColor($coordinates, $expectedColor)
 {
     $coordinates = array_map('trim', explode(',', $coordinates));
     $coordinates = array_map('intval', $coordinates);
     $expectedColor = strtolower($expectedColor);
     $imagick = new \Imagick();
     $imagick->readImageBlob((string) $this->getLastResponse()->getBody());
     $pixel = $imagick->getImagePixelColor($coordinates[0], $coordinates[1]);
     $color = $pixel->getColor();
     $toHex = function ($col) {
         return str_pad(dechex($col), 2, '0', STR_PAD_LEFT);
     };
     $hexColor = $toHex($color['r']) . $toHex($color['g']) . $toHex($color['b']);
     assertSame($expectedColor, $hexColor, 'Incorrect color at coordinate ' . implode(', ', $coordinates) . ', expected ' . $expectedColor . ', got ' . $hexColor);
 }
開發者ID:ASP96,項目名稱:imbo,代碼行數:18,代碼來源:ImboContext.php

示例14:

 /**
  * Fills an image area
  *
  * @param Imagick $image
  * @param int $x
  * @param int $y
  * @param color $color
  * @return bool
  */
 function zp_imageFill($image, $x, $y, $color)
 {
     $target = $image->getImagePixelColor($x, $y);
     return $image->floodFillPaintImage($color, 1, $target, $x, $y, false);
 }
開發者ID:ariep,項目名稱:ZenPhoto20-DEV,代碼行數:14,代碼來源:lib-Imagick.php

示例15: executeFilterImagick

 /**
  * Applies the image effect on an Imagick object. This function should be overridden by the effect.
  * @param \Imagick The image object to work with
  * @return \Imagick The new image object to use
  */
 protected function executeFilterImagick(\Imagick $imageData)
 {
     $imagePixel = $imageData->getImagePixelColor($this->pixelX, $this->pixelY);
     $imageData->paintTransparentImage($imagePixel, 0, $this->fuzzyNess);
     return $imageData;
 }
開發者ID:Superbeest,項目名稱:Core,代碼行數:11,代碼來源:PixelTransparentEffect.class.php


注:本文中的Imagick::getImagePixelColor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。