博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php图片上面写文字,输出图片
阅读量:4331 次
发布时间:2019-06-06

本文共 4455 字,大约阅读时间需要 14 分钟。

text = ! isset ( $showText ) ? $showText : $this->text; $this->show (); } function createText($instring) { $outstring = ""; $max = strlen ( $instring ); for($i = 0; $i < $max; $i ++) { $h = ord ( $instring [$i] ); if ($h >= 160 && $i < $max - 1) { $outstring .= substr ( $instring, $i, 2 ); $i ++; } else { $outstring .= $instring [$i]; } } return $outstring; } function show() { //输出头内容 Header ( "Content-type: image/png" ); //建立图象 //$image = imagecreate(400,300); $image = imagecreatefromjpeg ( "01.jpg" ); //这里的图片,换成你的图片路径 //定义颜色 $red = ImageColorAllocate ( $image, 255, 0, 0 ); $white = ImageColorAllocate ( $image, 255, 255, 255 ); $black = ImageColorAllocate ( $image, 0, 0, 0 ); //填充颜色 //ImageFilledRectangle($image,0,0,200,200,$red); //显示文字 $txt = $this->createText ( $this->text ); $txt0 = $this->createText ( $this->text0 ); $txt1 = $this->createText ( $this->text1 ); $txt2 = $this->createText ( $this->text2 ); $txt3 = $this->createText ( $this->text3 ); $txt4 = $this->createText ( $this->text4 ); //写入文字 imagettftext ( $image, $this->size, $this->angle, $this->showX, $this->showY, $white, $this->font, $txt ); imagettftext ( $image, $this->size, $this->angle0, $this->showX0, $this->showY0, $white, $this->font, $txt0 ); imagettftext ( $image, $this->size, $this->angle1, $this->showX1, $this->showY1, $white, $this->font, $txt1 ); imagettftext ( $image, $this->size, $this->angle2, $this->showX2, $this->showY2, $white, $this->font, $txt2 ); imagettftext ( $image, $this->size, $this->angle3, $this->showX3, $this->showY3, $white, $this->font, $txt3 ); imagettftext ( $image, $this->size, $this->angle4, $this->showX4, $this->showY4, $white, $this->font, $txt4 ); //ImageString($image,5,50,10,$txt,$white); //显示图形 imagejpeg ( $image ); imagegif ( $image, "a2.jpg" ); ImageDestroy ( $image ); } } ?>

改造后版本:背景图片自定义上传

multexts = $title_text; $this->bg = $bg; $this->show (); } function show() { //输出头内容 Header ( "Content-type: image/png" ); //建立图象 //$image = imagecreate(400,300); $image = imagecreatefromjpeg ( "./data/upload/".$this->bg); //这里的图片,换成你的图片路径 //定义颜色 $red = ImageColorAllocate ( $image, 255, 0, 0 ); $white = ImageColorAllocate ( $image, 255, 255, 255 ); $black = ImageColorAllocate ( $image, 0, 0, 0 ); //填充颜色 //ImageFilledRectangle($image,0,0,200,200,$red); foreach ($this->multexts as $tx){ imagettftext ( $image, $this->size, $tx['angle'], $tx['showX'], $tx['showY'], $black, $this->font, $tx['text'] ); } //显示图形 imagejpeg ( $image ); //imagegif ( $image, "a2.jpg" ); //ImageDestroy ( $image ); }}

控制器部分:

public function test2(){        $array = array(                    array('text'=>'aaaopop','angle'=>0,'showX'=>100,'showY'=>160),                    array('text'=>'bbb成果,没有任何','angle'=>0,'showX'=>100,'showY'=>190),                    array('text'=>'cccqqqqq踩踩','angle'=>0,'showX'=>100,'showY'=>220),                    array('text'=>'ddd 踩踩踩踩踩','angle'=>0,'showX'=>100,'showY'=>250),                );                $s = new ChinaText($array);            }public function test3(){        //$image = $_FILES['bg'];        $text = $_POST['text'];                //上传图片         //上传目录        $imagebg = $this->_upload($_FILES['bg'], '/');        if ($imagebg['error']) {            $this->error($imagebg['info']);        } else {            $data['imagebg'] = $imagebg['info'][0]['savename'];            //echo $data['imagebg'];        }                $title['showY']=100;        $title_text = array();                for ( $i=0;$i

html :

背景图片:
文字区域:

 

转载于:https://www.cnblogs.com/beyang/p/4826821.html

你可能感兴趣的文章
map() 方法创建一个新数组,其结果是该数组中的每个元素都调用一个提供的函数后返回的结果。...
查看>>
对象返回规范的url的两种方式的两种方式
查看>>
索引的利与弊
查看>>
【U3D】播放器设置(PlayerSettings)
查看>>
AngularJS过滤器
查看>>
用filter过滤数组对象,并统计过滤的项目
查看>>
RabbitMQ在Windows环境下的安装与使用
查看>>
架构、框架、模式和平台的区别
查看>>
selenium 服务器端运行命令
查看>>
selenium支付高版本的FireFox
查看>>
在服务器上排除问题的头五分钟
查看>>
win7下安装ubuntu14.04lts 双系统
查看>>
转multicast vs broadcast
查看>>
soapUI学习笔记---断言的小使用
查看>>
第二次作业
查看>>
WinCE7的Bootpart参考
查看>>
安装配置Django开发环境(Eclipse + Pydev)
查看>>
[蓝桥杯] 生日蜡烛
查看>>
Spring常用注解
查看>>
java 语法糖
查看>>