2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > php使用GD库实现文字图片水印及缩略图教程

php使用GD库实现文字图片水印及缩略图教程

时间:2021-01-03 11:48:48

相关推荐

php使用GD库实现文字图片水印及缩略图教程

php教程|PHP源码

image,this,quot,gt,info

php教程-PHP源码

缩略图可以通过gd库来实现,下面我们一起来看一个简单的php使用GD库实现文字图片水印及缩略图例子,希望此例子能够为大家带来有效的帮助。

ec(2);我们要使用gd库就必须先打开gd库,具体如下

仙落凡尘 源码,vscode调代码颜色,安装avd ubuntu,tomcat导入源代码,爬虫温度,php报错设置,天津seo优化找哪家,网站源码系统下载,简易html5个人介绍网页模板lzw

Windows下开启PHP的GD库支持

点餐web源码,ubuntu pe u盘,tomcat的端口号怎查看,爬虫网站播放量,php中利用css设置页面效果,SEO运营专家lzw

找到php.ini,打开内容,找到:

php电影搜索引擎源码,ubuntu没有桌面共享,淘宝爬虫代理池,php讲课,seo视频推荐lzw

;extension=php_gd2.dll

把最前面的分号“;”去掉,再保存即可,如果本来就没有分号,那就是已经开启了。

具体可以参考下文:/phper/php/48352.htm

一:添加文字水印 使用方法

require ‘image.class.php’

$src=”001.jpg”;

$content=”hello”;

$font_url=”my.ttf”;

$size=20;

$image=new Image($src);

$color=array(

0=>255,

1=>255,

2=>255,

2=>20

);

$local=array(

‘x’=>20,

‘y’=>30

);

$angle=10;

$image->fontMark($content,$font_url,$size,$color,$local,$angle);

$image->show();

二:图片缩略图 使用方法:

require ‘image.class.php’

$src=”001.jpg”;

$image=new Image($src);

$image->thumb(300,200);

$image->show();

三:image.class.php

class image{

private $info;

private $image;

public function __contruct($src){

$info= getimagesize($src);

$this->info=array(

‘width’=> $info[0],

‘height’=>$info[1],

‘type’=>image_type_to_extension($info[2],false),

‘mime’=>$info[‘mime’],

);

$fun=”imagecreatefrom{$this->info[‘type’]}”;

$this->image= $fun($src);

}

//缩略图

public function thumd($width,$height){

$image_thumb= imagecreatetruecolor($width,$height);

imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info[‘width’],$this->info[‘height’]);

imagedestroy($this->image);

$this->image=$image_thumb;

}

//文字水印

public function fontMark($content,$font_url,$size,$color,$local,$angle){

$col=imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);

$text=imagettftext($this->image,$size,$angle,$local[‘x’],$local[‘y’],$col,$font_url,$content);

}

//输出图片

public function show()

{

header(“Content-type:”,$this->info[‘mime’]);

$func=”image{$this->info[‘type’]}”;

$func($this->image);

}

public function save($nwename){

$func=”image{$this->info[‘type’]}”;

//从内存中取出图片显示

$func($this->image);

//保存图片

$func($this->image,$nwename.$this->info[‘type’]);

}

public function _destruct(){

imagedestroy($this->image);

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。