Need divergent thinking to learn PHP

Source: Internet
Author: User
Tags image identifier learn php resource
Beginner php! Look at this topic, I feel the title demon again! But I think, perhaps my idea may give everybody the study to some ideas!

Beginner php!
Look at this topic, I feel the title demon again!
But I think, perhaps my idea may give everybody the study to some ideas!

I think in the process of learning, we should know "play", create a sense of achievement, so that the effect of learning and enthusiasm will be very high,
Will be more like their own learning things!

An example is provided:

Today, I learned some functions of PHP's image function, and they are:

GetImageSize ()

Array getimagesize (string $filename [, Array & $imageinfo])
The getimagesize () function will determine any GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM or WBMP The size of the image file and returns the size of the image and the file type and a height/width text string that can be used in an IMG tag in a normal HTML file.

Imagecreatefromgif ()

Resource Imagecreatefromgif (String $filename)
Imagecreatefromgif () returns an image identifier that represents the image obtained from the given file name.
This function returns the handle of an operation in order to facilitate the use of this image resource later.
Similar functions include imagecreatefromjpeg (), Imagecreatefrompng () and, of course, a lot of them, you can read the official online handbook.

Imagecolorat ()

int Imagecolorat (resource $image, int $x, int $y)
Returns the color index value of the pixel at the specified position in the shape specified by image.

Imagecolorsforindex ()

Array Imagecolorsforindex (resource $image, int $index)
This function returns an associative array of key names with Red,green,blue and alpha that contains the corresponding values for the specified color index.

We saw a blunt introduction, estimated sleepy, but please hold on!

So after learning these functions, how to practice it?
In fact, I learned these functions, immediately thought of a very funny things can be done!
What is it? Guess what, ~!!!!.
Look at the code:

<?php
$url = "Logo-yy.gif";
$size = getimagesize ($url);
$width = $size [0];
$height = $size [1];
$im = Imagecreatefromgif ($url);


for ($y =1; $y < $height; $y + +) {
for ($x =1; $x < $width; $x + +) {
$color _index = Imagecolorat ($im, $x, $y);
$color _tran = Imagecolorsforindex ($im, $color _index);
Echo ("<span class=\" c\ "style=\" Color:rgb (". $color _tran[' Red '].", ". $color _tran[' green '. $color _tran[' Blue '. "); \" > ");
Echo ("Love");
Echo ("</span>");
}
Echo ("<br>");
}
?>

Note that the function used in my program is Imagecreatefromgif ()
So the file that the variable $url points to should be in GIF format, and if you want to point to a JPG file, use Imagecreatefromjpeg ()
Of course we can write together, because the first function can determine the format of the picture, I do not write here!! Ha ha
Well, there is a PHP environment to quickly try what is it! Oh

It is not recommended to use too large a picture! Small logo on the good!
Otherwise, don't blame me for not telling you!
This example has no practical use!! But he can inspire everyone to learn the fun!!
To the people who are learning PHP!



Related Article

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.