Rechercher une fonction PHP

ImagickPixel::isSimilar

(PECL imagick 2.0.0)

ImagickPixel::isSimilarCheck the distance between this color and another

Description

ImagickPixel::isSimilar ( ImagickPixel $color , float $fuzz ) : bool
Warning

This function is currently not documented; only its argument list is available.

Checks the distance between the color described by this ImagickPixel object and that of the provided object, by plotting their RGB values on the color cube. If the distance between the two points is less than the fuzz value given, the colors are similar. Deprecated in favour of ImagickPixel::isPixelSimilar().

PHP: ImagickPixel::isSimilar - Manual Home of Manuel PHP  Contents Haut

Parameters

color

The ImagickPixel object to compare this object against.

fuzz

The maximum distance within which to consider these colors as similar. The theoretical maximum for this value is the square root of three (1.732).

PHP: ImagickPixel::isSimilar - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 ImagickPixel::isSimilar()

<?php
        
// 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)',   $root3,         false,],
            [
'rgb(245, 0, 0)',      'rgb(255, 0, 0)',  10 $root3,         true,],
            [
'rgb(0, 0, 0)',        'rgb(7, 7, 0)',     $root3,         false,],
            [
'rgb(0, 0, 0)',        'rgb(7, 7, 0)',    10 $root3,         true,],
            [
'rgba(0, 0, 0, 1)',    'rgba(7, 7, 0, 1)'$root3,         false,],
            [
'rgba(0, 0, 0, 1)',    'rgba(7, 7, 0, 1)',    10 $root3,     true,],
            [
'rgb(128, 128, 128)',  'rgb(128, 128, 120)',   $root3,     false,],
            [
'rgb(128, 128, 128)',  'rgb(128, 128, 120)',   $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>
                <tr>
                <th>
                Color 1
                </th>
                <th>
                Color 2
                </th>
                <th>
                    Test distance * 255
                </th>
                <th>
                    Is within distance
                </th>
                </tr>
        </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>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                <td style='text-align: center;'>%s</td>
            </tr>"
;
            
            
$output .= sprintf(
                
$layout,
                
$color1,
                
$color2,
                
$distance,
                
$isSimilar 'yes' 'no'
            
);
        }

        
$output .= "</tbody></table>";
        
        return 
$output;

?>

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-imagickpixel.issimilar.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut