PHP利用GD库画图和生成验证码图片
首先得确定php.ini设置有没有打开GD扩展功能,测试如下
print_r(gd_info());
如果有打印出内容如下,则说明GD功能有打开:
Array( [GD Version] => bundled (2.0.34 compatible) [FreeType Support] => 1 [FreeType Linkage] => with freetype [T1Lib Support] => 1 [GIF Read Support] => 1 [GIF Create Support] => 1 [JPG Support] => 1 [PNG Support] => 1 [WBMP Support] => 1 [XPM Support] => [XBM Support] => 1 [JIS-mapped Japanese Font Support] => )
GD画图一般步骤如下:
1.创建一张画布资源
2.创建颜色画笔
3.画图
4.保存图片或输出图片
5.销毁内存画布资源
测试代码如下:
<?phpheader ("Content-type: image/jpeg");$width = 400; //宽,高$height = 400; $image = imagecreate($width, $height); //第一步:创建空白图像$white = imagecolorallocate($image, 0, 0, 0); //第一次对 imagecolorallocate() 的调用会给基于调色板的图像填充背景色,即用 imagecreate() 建立的图像。 $green = imagecolorallocate($image, 0, 255, 0); //第二步:为图像分配颜色imageline($image, 0, 20, 400, 20, $green); //第三步:画线imagerectangle($image,100,40,300,100,$green); //画矩形imagearc($image, 200, 150, 90, 90, 0, 360, $green); //画圆imagestring($image, 14, 100, 240, "PHP is NiuBi HongHong!", $green); //写字符串$str="abcdefghjklmnpqrstuvwxyz23456789";$randstr = substr(str_shuffle($str), 0,4);imagestring($image, 14, 100, 260, $randstr, $green); //验证码imagettftext($image, 14, 0, 100, 300, $green, './MSJHBD.TTF', "中文vsEnglish"); //中文验证// imagejpeg($image,'./test.jpg'); //在当前路径下保存图片为test.jpgimagejpeg($image); //第四步:不加文件名,直接输出到网页 imagedestroy($image); //第五步:销毁,回收资源?>
测试图片如下:
注:GD库强大的可以画各种报表(如柱状图,饼状图等)、缩略图、加水印图和股票走势图
缩略图功能例子:
<?phpheader ("Content-type: image/png");$width = 300; //原图宽,高$height = 210; $thumb_width = (int)$width/2;$thumb_height = (int)$height/2;$dst = imagecreate($thumb_width,$thumb_height); //创建缩略图画布$gray = imagecolorallocate($dst, 100, 100, 100);$src = imagecreatefrompng('./me.png'); //读取原图//把原图copy到缩略图画布上imagecopyresampled($dst, $src, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); imagepng($dst,'./me_thumb.png');imagedestroy($dst);imagedestroy($src);?>

本文将介绍七种利用免费的BingImageCreator获得高质量输出的方法。BingImageCreator(现称为MicrosoftDesigner的ImageCreator)是一个出色的在线人工智能艺术生成器之一。它能根据用户的提示生成高度逼真的视觉效果。提示越具体、清晰和创意,生成的效果也会更出色。BingImageCreator在创建高质量图像方面取得了重大进展。它现在使用Dall-E3培训模式,显示出更高水平的细节和现实主义。然而,它能否始终如一地生成高清结果取决于几个因素,包括快速

小米手机image怎么删除?在小米手机中是可以删除image,但是多数的用户不知道image如何的删除,接下来就是小编为用户带来的小米手机image删除方法教程,感兴趣的用户快来一起看看吧!小米手机image怎么删除1、首先打开小米手机中的【相册】功能;2、然后勾选不需要的图片,点击右下角的【删除】按钮;3、之后点击最顶部的【相册】进入到专区,选择【回收站】;4、接着直接点击下图所示的【清空回收站】;5、最后直接点击【永久删除】即可完成。

在html5中,width的意思是宽度,width属性定义元素内容区的宽度,在内容区外面可以增加内边距、边框和外边距,只需要给元素设置“元素{width:数值}”即可。

LINUX是一种开源的操作系统,它的灵活性和可定制性使得它成为了许多开发者和系统管理员的首选,在LINUX系统中,图像处理是一个非常重要的任务,而Imagemagick和Image是两个非常流行的图像处理工具,本文将为您介绍如何在Centos系统中安装Imagemagick和Image,并提供详细的安装教程。Imagemagic安装Centos教程Imagemagick是一个功能强大的图像处理工具集,它可以在命令行下执行各种图像操作,以下是在Centos系统上安装Imagemagick的步骤:1

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

CSS维度属性详解:height和width在前端开发中,CSS是一种强大的样式定义语言。其中,height和width是两个最基本的维度属性,用于定义元素的高度和宽度。本文将对这两个属性进行详细解析,并提供具体的代码示例。一、height属性height属性用于定义元素的高度。可以使用像素(pixel)、百分比(percentage)或者

方法有像素值、百分比、em单位、rem单位、vw/vh单位、auto、fit-content、min-content、max-content。详细介绍:1、像素值(px):像素值是固定的,不论屏幕分辨率如何变化,它的宽度都是不变的。例如:width: 300px;2、百分比(%):百分比宽度是相对于父元素的宽度的。例如:width: 50%;3、em单位等等。

imagefilledrectangle()函数绘制一个填充矩形。语法imagefilledrectangle($img,$x1,$y1,$x2,$y2,$color)参数image 使用imagecreatetruecolor()创建一个空白图像。x1点1的x坐标。y1 点1的y坐标。x2 点2的x坐标。y2 点2的y坐标。color 填充颜色。返回值imagefilledrectangle()函数成功返


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools