search
Homephp教程php手册动态图像处理 — php(34),动态图像处理php34

动态图像处理 — php(34),动态图像处理php34

1 PHP中GD库的使用

PHP 不仅限于只产生HTML 的输出,还可以创建及操作多种不同格式的图像文件。PHP提供了一些内置的图像信息函数,也可以使用GD函数库创建新图像或处理已有的图像。目前GD2库支持JPEG、PNG和WBMP格式。但不再支持GIF格式。

• JPEG 是一种压缩标准的名字,通常是用来存储照片或者存储具有丰富色彩和色彩层次的图像。这种格式使用了有损压缩。

• PNG 是可移植的网络图像,对图像采用了无损压缩标准。

• WBMP是专门为无线通讯设备设计的文件格式。但是并没有得到广泛应用。

2 图像的生成步骤

在PHP中创建一个图像应该完成如下所示的4个步骤:
1.创建一个背景图像(也叫画布),以后的操作都基于此背景图像。
2.在背景上绘制图像轮廓或输入文本。
3.输出最终图形
4.释放资源

<span><?<span>php
</span><span>//</span><span> 创建背景图像</span>
$height = <span>200</span><span>;
$width </span>= <span>200</span><span>;
$im </span>= ImageCreateTrueColor($width, $height); <span>//</span><span>建立空白背景</span>
$white = ImageColorAllocate ($im, <span>255</span>, <span>255</span>, <span>255</span>);<span>//</span><span>设置绘图颜色</span>
$blue = ImageColorAllocate ($im, <span>0</span>, <span>0</span>, <span>64</span><span>);
imageFill($im, </span><span>0</span>, <span>0</span>, $blue);<span>//</span><span>绘制背景</span>
imageLine($im, <span>0</span>, <span>0</span>, $width, $height, $white); <span>//</span><span>画线</span>
imageString($im, <span>4</span>, <span>50</span>, <span>150</span>, <span>'</span><span>Sales</span><span>'</span>, $white); <span>//</span><span>添加字串</span>
header(<span>'</span><span>Content-type: image/png</span><span>'</span><span>);
imagePng($im); </span><span>//</span><span>以PNG 格式将图像输出</span>
<span>imageDestroy($im);
</span>?></span>

3 画布管理

imagecreate--新建一个基于调色板的图像

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
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use