search
Homephp教程php手册php画图实例,画图实例

php画图实例,画图实例

本文实例讲述了php画图的方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:

// by MoreWindows
$imgWidth = 600; 
$imgHeight = 400; 
$img = imagecreatetruecolor($imgWidth, $imgHeight); 
imagefill($img, 0, 0, imagecolorallocate($img, 240, 240, 240));//设置底色 
$snowflake_size = 30; 
$font_file = "c:\\WINDOWS\\Fonts\\simhei.ttf";  
//生成大雪花 其实就是调用imagettftext()输出*号 
for ($i=1; $i { 
    $font_color = imagecolorallocate($img, mt_rand(100,200), mt_rand(100,200), mt_rand(100,200)); 
    imagettftext($img, $snowflake_size, mt_rand(0, 180), mt_rand(0, $imgWidth),mt_rand(0, $imgHeight), $font_color, $font_file, "□");  

//水印文字 
$black_color = imagecolorallocate($img, 0, 0, 0); 
imagettftext($img, 12, 0, $imgWidth - 50 , $imgHeight - 20, $black_color, $font_file, "PHP画图"); 
imagepng($img); 
imagedestroy($img); 
?>

本实例运行效果如下图所示

更多请参考:
http://www.php.net/manual/zh/refs.utilspec.image.php

希望本文所述对大家的PHP程序设计有所帮助。

PHP不可以实现画图功可以

先把header放在最前面,再试下。如果不行,请回报错误。
header("Content-Type:image/gif");
$img=imagecreatetruecolor(50,50);
 

PHP画图的问题,急

1)首先检查自己的PHP又没有开始GD库的支持。如果是windows系统,
直接把php.ini中extension=php_gd2.dll前面的分号去掉就行。
如果是linux系统,请查php参考手册关于GD库的安装说明

2)代码示例如下:

// 创建一个520*300的图片,
$im = imagecreatetruecolor(520, 300);
imagefilledrectangle($im, 0, 0, 520, 300, 0xFFFFFF);
imageline($im,10,270,510,270,0x000000);
......

// Save the image to file and free memory
imagepng($im, 'photo_stamp.png');
imagedestroy($im);
?>
3) 依次画其他系统即可。
 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools