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


PHP ImagickPixel::isPixelSimilar方法代码示例

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


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

示例1: render

 public function render()
 {
     //Example ImagickPixel::isSimilar
     // The tests below are written with the maximum distance expressed as 255
     // so we need to scale them by the square root of 3 - the diagonal length
     // of a unit cube.
     $root3 = 1.732050807568877;
     $tests = array(['rgb(245, 0, 0)', 'rgb(255, 0, 0)', 9 / $root3, false], ['rgb(245, 0, 0)', 'rgb(255, 0, 0)', 10 / $root3, true], ['rgb(0, 0, 0)', 'rgb(7, 7, 0)', 9 / $root3, false], ['rgb(0, 0, 0)', 'rgb(7, 7, 0)', 10 / $root3, true], ['rgba(0, 0, 0, 1)', 'rgba(7, 7, 0, 1)', 9 / $root3, false], ['rgba(0, 0, 0, 1)', 'rgba(7, 7, 0, 1)', 10 / $root3, true], ['rgb(128, 128, 128)', 'rgb(128, 128, 120)', 7 / $root3, false], ['rgb(128, 128, 128)', 'rgb(128, 128, 120)', 8 / $root3, true], ['rgb(0, 0, 0)', 'rgb(255, 255, 255)', 254.9, false], ['rgb(0, 0, 0)', 'rgb(255, 255, 255)', 255, true], ['rgb(255, 0, 0)', 'rgb(0, 255, 255)', 254.9, false], ['rgb(255, 0, 0)', 'rgb(0, 255, 255)', 255, true], ['black', 'rgba(0, 0, 0)', 0.0, true], ['black', 'rgba(10, 0, 0, 1.0)', 10.0 / $root3, true]);
     $output = "<table width='100%' class='infoTable'><thead>\n                <tr>\n                <th>\n                Color 1\n                </th>\n                <th>\n                Color 2\n                </th>\n                <th>\n                    Test distance * 255\n                </th>\n                <th>\n                    Is within distance\n                </th>\n                </tr>\n        </thead>";
     $output .= "<tbody>";
     foreach ($tests as $testInfo) {
         $color1 = $testInfo[0];
         $color2 = $testInfo[1];
         $distance = $testInfo[2];
         $expectation = $testInfo[3];
         $testDistance = $distance / 255.0;
         $color1Pixel = new \ImagickPixel($color1);
         $color2Pixel = new \ImagickPixel($color2);
         $isSimilar = $color1Pixel->isPixelSimilar($color2Pixel, $testDistance);
         if ($isSimilar !== $expectation) {
             echo "Test distance failed. Color [{$color1}] compared to color [{$color2}] is not within distance {$testDistance} FAILED." . NL;
         }
         $layout = "<tr>\n                <td>%s</td>\n                <td>%s</td>\n                <td>%s</td>\n                <td style='text-align: center;'>%s</td>\n            </tr>";
         $output .= sprintf($layout, $color1, $color2, $distance, $isSimilar ? 'yes' : 'no');
     }
     $output .= "</tbody></table>";
     return $output;
     //Example end
 }
开发者ID:finelinePG,项目名称:imagick,代码行数:29,代码来源:isPixelSimilar.php

示例2: array

<?php

$root3 = 1.732050807568877;
$tests = array(array('rgb(245, 0, 0)', 'rgb(255, 0, 0)', 9 / $root3, false), array('rgb(245, 0, 0)', 'rgb(255, 0, 0)', 10 / $root3, true), array('rgb(0, 0, 0)', 'rgb(7, 7, 0)', 9 / $root3, false), array('rgb(0, 0, 0)', 'rgb(7, 7, 0)', 10 / $root3, true), array('rgba(0, 0, 0, 1)', 'rgba(7, 7, 0, 1)', 9 / $root3, false), array('rgba(0, 0, 0, 1)', 'rgba(7, 7, 0, 1)', 10 / $root3, true), array('rgb(128, 128, 128)', 'rgb(128, 128, 120)', 7 / $root3, false), array('rgb(128, 128, 128)', 'rgb(128, 128, 120)', 8 / $root3, true), array('rgb(0, 0, 0)', 'rgb(255, 255, 255)', 254.9, false), array('rgb(0, 0, 0)', 'rgb(255, 255, 255)', 255, true), array('rgb(255, 0, 0)', 'rgb(0, 255, 255)', 254.9, false), array('rgb(255, 0, 0)', 'rgb(0, 255, 255)', 255, true), array('black', 'rgba(0, 0, 0)', 0.0, true), array('black', 'rgba(10, 0, 0, 1.0)', 10.0 / $root3, true));
try {
    foreach ($tests as $testInfo) {
        $color1 = $testInfo[0];
        $color2 = $testInfo[1];
        $distance = $testInfo[2];
        $expectation = $testInfo[3];
        $testDistance = $distance / 255.0 + 1.0E-8;
        $color1Pixel = new ImagickPixel($color1);
        $color2Pixel = new ImagickPixel($color2);
        $isSimilar = $color1Pixel->isPixelSimilar($color2Pixel, $testDistance);
        if ($isSimilar !== $expectation) {
            echo "isPixelSimilar failed. Color [{$color1}] compared to color [{$color2}]" . " is not within distance {$testDistance}." . PHP_EOL;
        }
    }
    echo "success";
} catch (\Exception $e) {
    echo "Exception caught in ImagickPixel::isPixelSimilar test: " . $e->getMessage() . PHP_EOL;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:22,代码来源:024_ispixelsimilar.php

示例3: ImagickPixel

try {
    $pixel = new ImagickPixel('the-best-color-in-the-world');
} catch (ImagickPixelException $ex) {
    echo "__construct\n";
}
$pixel = new ImagickPixel('white');
try {
    $pixel->setColor('the-worst-color-in-the-world');
} catch (ImagickPixelException $ex) {
    echo "setColor\n";
}
define('IMAGICK_COLOR_INVALID', -1);
try {
    $pixel->getColorValue(IMAGICK_COLOR_INVALID);
} catch (ImagickPixelException $ex) {
    echo "getColorValue\n";
}
try {
    $pixel->setColorValue(IMAGICK_COLOR_INVALID, 0);
} catch (ImagickPixelException $ex) {
    echo "setColorValue\n";
}
try {
    $pixel->isPixelSimilar(new ImagickPixelException(), 0);
} catch (ImagickPixelException $ex) {
    echo "isPixelSimilar\n";
}
?>
==DONE==
开发者ID:badlamer,项目名称:hhvm,代码行数:29,代码来源:pixel_exception.php

示例4: sqrt

<?php

$sqrt3 = sqrt(3);
$pixel = new ImagickPixel('red');
var_dump($pixel->isPixelSimilar($pixel, 0));
var_dump($pixel->isPixelSimilar('red', 0));
var_dump($pixel->isPixelSimilar('#FF0000', 0));
var_dump($pixel->isPixelSimilar('rgb(255, 0, 0)', 0));
var_dump($pixel->isPixelSimilar('green', 0.01));
var_dump($pixel->isPixelSimilar('#0000FF', 0.02));
var_dump($pixel->isPixelSimilar('rgb(0, 0, 0)', 0.03));
$pixel = new ImagickPixel('#F02B88');
var_dump($pixel->isPixelSimilar('#F02B89', 0.9 / $sqrt3 / 255));
var_dump($pixel->isPixelSimilar('#F02B89', 1.1 / $sqrt3 / 255));
var_dump($pixel->isPixelSimilar('#F12A86', 0.9 / 255));
var_dump($pixel->isPixelSimilar('#F12A88', 1.1 / 255));
?>
==DONE==
开发者ID:badlamer,项目名称:hhvm,代码行数:18,代码来源:pixel_issimilar.php


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