1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="imagickpixel.issimilar">
<refnamediv>
<refname>ImagickPixel::isSimilar</refname>
<refpurpose>Check the distance between this color and another</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>bool</type><methodname>ImagickPixel::isSimilar</methodname>
<methodparam><type>ImagickPixel</type><parameter>color</parameter></methodparam>
<methodparam><type>float</type><parameter>fuzz</parameter></methodparam>
</methodsynopsis>
&warn.undocumented.func;
<para>
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 <link linkend="imagickpixel.ispixelsimilar">ImagickPixel::isPixelSimilar()</link>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>color</parameter></term>
<listitem>
<para>
The ImagickPixel object to compare this object against.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>fuzz</parameter></term>
<listitem>
<para>
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).
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&imagick.return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title> <function>ImagickPixel::isSimilar</function></title>
<programlisting role="php">
<![CDATA[
<?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)', 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>
<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;
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|