PHP GD Library parses a simple picture and outputs

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.