PHP image Processing

Source: Internet
Author: User

To add a feature to a recent project, the user is wearing a device that captures the location and physical condition of the person and displays the data on the map. It seems like a good idea, but now there is no such device AH (pit daddy), can only simulate the data. And with the data to show more people on the map, also need a different icon, the initial idea is to use the user's number to identify. Make it look the same (this is the effect of the finish).

PHP is a little more familiar with, it is done with PHP,

Need to prepare a picture, from the Internet, the appropriate size of the reduction, and then began to use the program to generate the "

1, first need to get a picture resources

$im = imagecreatefrompng (' your.png ');

The parameter is the picture address that you prepare, because our picture is the PNG format, the PNG picture background is transparent, therefore all uses it. There are other functions, imagecreatefromjpeg, imagecreatefromgif and so on.

2, assign a color, here is white, the last three parameters is the value of RGB.

$color = imagecolorallocate ($im, 255, 255, 255);

3, write on the picture.

Imagettftext ($im$color, ' Monaco.ttf ', ' 10 ');

The parameters are: Picture resource, font size, text tilt, text position x, text position y, color, font file, text content. Where the text position is relative to the upper-left corner of the picture.

4. Output

Imagepng ($im);

If the second argument is omitted, the picture is exported to the browser. The second parameter is the storage location.

After doing this, I found that, wow, the picture has a background, we want to be transparent, on-line search, there is such a function:

Imagesavealpha ($imtrue);

So there's no background, it's transparent.

The complete code is as follows:

$im = imagecreatefrompng (' your.png '); Imagesavealpha ($imtrue); $color = imagecolorallocate ($im, 255, 255, 255); Imagettftext ($im$color , ' Monaco.ttf ', ' ten'); Imagepng ($im);

If you want to get more than one, you can cycle, then adjust the text position, output, look at my:

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.