search
Homephp教程php手册php图形处理教程-php生成图片(1/4)

php图形处理教程-php生成图片(1/4)

Jun 13, 2016 am 09:48 AM
phpwebFunctiongraphics processingpictureexistapplicationTutorialgenerate

在web应用中经常会用到生成图片这一功能,在php教程 中创建图片需要gd库的支持才能创建图形,有了这个图形功能,我们就可以方便的生成缩图,验证码,给图片加水印等。

在php中要安装gd库才能正常运行创建图片功能,方法如下,在win系统,找到php.ini把

;extension=php_gd2.dll前面的";"去了,重起apache就OK了。

下面我们一看实例

php的gd库可以生成多种图像文件,如gif,png,jpg,wbmp,xpm等,下面来看一个生成正方形的文件。

$height = 300;
$width = 300;
//创建背景图
$im = ImageCreateTrueColor($width, $height);
//分配颜色
$white = ImageColorAllocate ($im, 255, 255, 255);
$blue = ImageColorAllocate ($im, 0, 0, 64);
//绘制颜色至图像中
ImageFill($im, 0, 0, $blue);
//绘制字符串:Hello,PHP
ImageString($im, 10, 100, 120, 'Hello,PHP', $white);
//输出图像,定义头
Header ('Content-type: image/png');
//将图像发送至浏览器
ImagePng($im);
//清除资源
ImageDestroy($im);
?>

查看结果只要浏览php文件就可以了,如果要图像调用php图形处理教程-php生成图片(1/4)

实例二,使用基本函数创建图片imagecreate()

resource imagescreate(int x,inty)

imagedestroy 是放图片所占内存空间

int ingaedestroy( image)

imagecopy()

int imagecopy( dst_im,sr_im,int x,int y,int x,int y,)

1 2 3 4

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

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.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool