Home  >  Article  >  Backend Development  >  Create simple images in PHP through the GD library (detailed explanation with pictures and text)

Create simple images in PHP through the GD library (detailed explanation with pictures and text)

烟雨青岚
烟雨青岚forward
2020-06-12 09:28:142187browse

Create simple images in PHP through the GD library (detailed explanation with pictures and text)

Create a simple picture through PHP’s GD library

1. Effect drawing

Create simple images in PHP through the GD library (detailed explanation with pictures and text)

2. The code is as follows:

<?php
// PHP 使用 GD 拓展库制作图像
// 指定输出为 JPEG 图片
header(&#39;Content-type:image/jpeg&#39;);
// 1、创建图像
// imagecreatetruecolor($width, $height)
$img = imagecreatetruecolor(200, 200);
// 2、绘制图像
// 2.1 分配颜色
$color = imagecolorallocate($img, 114, 12, 114);
// 2.2 填充颜色
imagefill($img, 0, 0, $color);
// 3、输出图像,第二个参数表示文件名,如果有第二个参数则将直接保存图像而不显示   &#39;image/tupian.jpg&#39; => 相对位置  &#39;/home/image/tupian.jpg&#39; => 绝对位置,相对于系统
imagejpeg($img);
// 4、释放资源
imagedestroy($img);

3. The address of the file can be used as an image The address is written in HTML and displayed

Thank you all for reading, I hope you will benefit a lot.

This article is reproduced from: https://www.cnblogs.com/GetcharZp/p/12260075.html

Recommended tutorial: "php tutorial"

The above is the detailed content of Create simple images in PHP through the GD library (detailed explanation with pictures and text). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51dev.com. If there is any infringement, please contact admin@php.cn delete