This article mainly introduces the PHP GD library to parse a simple picture and output, has a certain reference value, now share to everyone, have the need for friends can refer to
Here are just a few pictures of 2 color values, a simple description of the concept.
First, install the next GD library. Otherwise the following code will not work.
$size = getimagesize (' 2.png '); Get picture size $res = imagecreatefrompng (' 2.png '); Gets the resource object for the specified picture for ($i = 0; $i < $size [1]; + + $i) {for ($j = 0; $j < $size [0]; + + $j) { $rgb = Imageco Lorat ($res, $i, $j); Gets the coordinate index $rgbarray = Imagecolorsforindex ($res, $RGB);//Gets the RGB color of each coordinate $sum = $rgbarray [' red '] + $rgbarray [' Green '] + $rgbarray [' Blue ']; RGB color value added, mainly in order to differentiate /** * Demo picture has pure black rgb (0,0,0) color and other color composition */ if ($sum = = 0) { $data [$i] [$j] = 1; } else { $data [$i] [$j] = 2; }}
The code above has generated a block of color for each pixel of the entire picture.
echo "<p style= ' border:1px solid #ccc; width: {$size [1]}px;height: {$size [0]}px; '] > "; for ($i = 0; $i < count ($data), $i + +) { if (array_sum ($data [$i])! =) {for ($j = 0; $j < count ($data [ $i]); $j + +) { if ($data [$i] [$j] = = 1) { echo ' <p style= "width:1px;height:1px;background: #cccccc; float:left;" ></p> '; } else { echo ' <p style= ' width:1px;height:1px;background:red;float:left; ></p> '; }}} } echo "</p>";
The above code allows you to generate a picture that is stacked with the pixel block as specified.
the Similar_text function can determine the similarity of 2 values. I'll consider whether I can use the binary code of the A picture and the B-picture. Judging the similarity.
Just a concept, and then continue to study, so that you can achieve the function of word recognition.
Related recommendations:
Nginx and PHP installation and configuration five Linux with phpize install PHP gd extension
php GD Library Add FreeType extension method