Home >Backend Development >PHP Tutorial >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
2. The code is as follows:
<?php // PHP 使用 GD 拓展库制作图像 // 指定输出为 JPEG 图片 header('Content-type:image/jpeg'); // 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、输出图像,第二个参数表示文件名,如果有第二个参数则将直接保存图像而不显示 'image/tupian.jpg' => 相对位置 '/home/image/tupian.jpg' => 绝对位置,相对于系统 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!