Home > Backend Development > PHP Tutorial > 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)

烟雨青岚
Release: 2023-04-08 20:58:01
forward
2397 people have browsed it

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);
Copy after login

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!

Related labels:
source:51dev.com
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template