ImagickPixel::isSimilar

(PECL imagick 2, PECL imagick 3)

ImagickPixel::isSimilarCheck the distance between this color and another

Beschreibung

public ImagickPixel::isSimilar(ImagickPixel $color, float $fuzz): bool
Warnung

Diese Funktion ist bis jetzt nicht dokumentiert. Es steht nur die Liste der Argumente zur Verfügung.

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().

Parameter-Liste

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).

Rückgabewerte

Liefert true bei Erfolg.

Beispiele

Beispiel #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;

?>

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Definition von Stored Procedures - eine Einführung

Stored Procedures sind vordefinierte SQL-Codeblöcke, die in einer Datenbank gespeichert sind und bei Bedarf aufgerufen werden können. ...

Bernie

Autor : ebiz-consult GmbH & Co. KG
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

What defines Laravel's developer community?

What factors contribute to the perceived happiness within the Laravel developer community, and how does this compare to other developer communitie ...

Geschrieben von BakhamMamodar am 01.05.2024 10:45:23
Forum: PHP Developer Forum
"How to warm cold entrance?"

What are some effective strategies for addressing the significant heat loss occurring in the entrance hall, which is noticeably the coldest area o ...

Geschrieben von NeerMohan am 01.05.2024 06:49:27
Forum: Fragen/Vorschläge zum Forum
Berechnungen durchführen

Hallo liebe Forenmitglieder, meine erste frage ist zum Aufbau meiner kleinen Berechnungswebseite, nichts kommerzielles, soll nur eine Anwendung f ...

Geschrieben von matze511 am 21.04.2024 21:42:37
Forum: PHP Developer Forum
Professioneller Webentwickler & Webdesigner

Of course, here is the translation: Hello, Thank you for your interest in the long-term project. Your extensive skills and experience in web dev ...

Geschrieben von Athelstan am 15.04.2024 09:25:39
Forum: Jobgesuche