PHP合成图片、生成文字、居中对齐、画线、矩形、三角形、多边形、图片抗锯齿、不失真 高性能源码示例
function generateImg($source, $text1, $text2, $text3, $font = './msyhbd.ttf') {
$date = '' . date ( 'Ymd' ) . '/';
$img = $date . md5 ( $source . $text1 . $text2 . $text3 ) . '.jpg';
if (file_exists ( './' . $img )) {
return $img;
} $main = imagecreatefromjpeg ( $source ); $width = imagesx ( $main );
$height = imagesy ( $main ); $target = imagecreatetruecolor ( $width, $height ); $white = imagecolorallocate ( $target, 255, 255, 255 );
imagefill ( $target, 0, 0, $white ); imagecopyresampled ( $target, $main, 0, 0, 0, 0, $width, $height, $width, $height ); $fontSize = 18;//像素字体
$fontColor = imagecolorallocate ( $target, 255, 0, 0 );//字的RGB颜色
$fontBox = imagettfbbox($fontSize, 0, $font, $text1);//文字水平居中实质
imagettftext ( $target, $fontSize, 0, ceil(($width - $fontBox[2]) / 2), 190, $fontColor, $font, $text1 ); $fontBox = imagettfbbox($fontSize, 0, $font, $text2);
imagettftext ( $target, $fontSize, 0, ceil(($width - $fontBox[2]) / 2), 370, $fontColor, $font, $text2 ); $fontBox = imagettfbbox($fontSize, 0, $font, $text3);
imagettftext ( $target, $fontSize, 0, ceil(($width - $fontBox[2]) / 2), 560, $fontColor, $font, $text3 ); //imageantialias($target, true);//抗锯齿,有些PHP版本有问题,谨慎使用 imagefilledpolygon ( $target, array (10 + 0, 0 + 142, 0, 12 + 142, 20 + 0, 12 + 142), 3, $fontColor );//画三角形
imageline($target, 100, 200, 20, 142, $fontColor);//画线
imagefilledrectangle ( $target, 50, 100, 250, 150, $fontColor );//画矩形 //bof of 合成图片
$child1 = imagecreatefromjpeg ( 'http://gtms01.alicdn.com/tps/i1/T1N0pxFEhaXXXxK1nM-357-88.jpg' );
imagecopymerge ( $target, $child1, 0, 400, 0, 0, imagesx ( $child1 ), imagesy ( $child1 ), 100 );
//eof of 合成图片 @mkdir ( './' . $date );
imagejpeg ( $target, './' . $img, 95 ); imagedestroy ( $main );
imagedestroy ( $target );
imagedestroy ( $child1 );
return $img;
}
//http://my.oschina.net/cart/
generateImg ( 'http://1.popular.sinaapp.com/munv/pic.jpg', 'my.oschina.net/cart', 'PHP文字水平居中', '3个字' );
exit ();
PHP合成图片、生成文字、居中对齐、画线、矩形、三角形、多边形、图片抗锯齿、不失真 高性能源码示例的更多相关文章
- 【css对齐】块内或者行内图片与文字居中对齐最靠谱的方式!
块内或者行内图片与文字居中对齐最靠谱的方式! 做图片与文字在一行的按钮时候最常用到,总结了一个靠谱的方法,终于可以完美的对齐下面给个代码 首先是html: <p class="btnU ...
- HTML5[8]: 图文混排,图片与文字居中对齐
<img src="image.png"><span>999</span> img { /* ... */ vertical-align: t ...
- PHP生成小程序二维码合成图片生成文字
这部分代码是写在项目上的代码,THINKPHP3.1如果迁移到其他的地方应该要稍稍改动一下以适合自己的项目 function get_bbox($text,$fsize,$ffile){ return ...
- 问题2:css图片、文字居中
1. 文本或图片水平对齐:父元素中添加以下样式 text-align : center;2. 单行文字垂直对齐:父元素中添加以下样式 line-height : 父元素高度; 3.图片 ...
- vue小组件练习之文字居中对齐组件
时隔多月,继续学习Vue,这次是一个组件的制作过程 先让我们来看一下组件的预期效果 上图为公司自营的一个微信商城的某一部分截图,可以看到红框内部分的文字多行与单行是居中对齐的,我们现在要做的就是使用V ...
- TextView展示富文本时emoj或图片和文字不对齐的解决方案
在项目中,回复框.聊天界面的显示往往会有emoj或者图片,但是一个比较头疼的问题是,会出现emoj表情或者图片和文字的位置不对齐,总是有偏移,这样很影响用户体验的.下面会总结一下如何解决这个问题. 本 ...
- [Android]Android 布局中如何让图片和文字居中显示?
图片文字居中显示 **①组件TextView的属性 drawableTop ``` <LinearLayout android:layout_width="match_parent&q ...
- PHP 图片生成文字
$dst_path = './1.png'; $font_file = './ADOBEHEITISTD-REGULAR (V5.010).OTF'; $img_bg = imagecreatefro ...
- align使图片和文字居中
<img src=... align=absmiddle />
随机推荐
- 移动前端头部标签(HTML5 meta)
在移动前端开发中添加一些webkit专属的HTML5头部标签,帮助浏览器更好解析html代码 <!DOCTYPE html> 使用 HTML5 doctype,不区分大小写 <he ...
- 数据库数据怎样导出成Excle表格或Word文档?
数据导出:将数据库的数据导出成Excel工作表或Word文档 方法:将一个泛型集合导出出去 主要使用: SaveFileDialog StreamWriter 导出代码: private void b ...
- Sql 查找整个数据库中的字符串
--存储过程 CREATE PROCEDURE [dbo].[SP_FindValueInDB] ( @value VARCHAR() ) AS BEGIN SET NOCOUNT ON; DECLA ...
- tomcat各种问题汇总
1. 让Tomcat支持中文路径名和中文文件名 因为内置get协议中的URL编码都是ISO-8859-1,所以需要我们强制编码,在tomcat/conf/Server.xml中添加URIEncodin ...
- Ubuntu遇到Please ensure that adb is correctly located at '...adb.exe' and can be executed 问题解决方法
上次我们在SDK更新的到最新的Android L版本之后,我发现我的ADT和android指定的版本不对应,我的ADT是22版本的,android L需要23版本以上的,版本不对应的话就无法加载这个S ...
- protoc-gen-php --php_out: protoc-gen-php: Plugin output is unparseable.
背景 业务需要用protobuffer 进行通讯. client: php server: c++ 在github 上找到 Protobuf-PHP (https://github.com/drslu ...
- 纵表、横表互转的SQL
纵表.横表互转的SQL By:大志若愚 1.建表: 纵表结构 Table_A create table Table_A ( 姓名 ), 课程 ), 成绩 int ) ) ) ) ) ) 姓名 课程 ...
- Android打包签名
Ⅰ.用jdk和sdk自带工具打包签名 a.把jdk下的keytool.exe和jarsigner.exe所在目录(两个工具在同一目录) 添加到环境变量path 1)新建环境变量package,pack ...
- shell 脚本注意事项
设脚本名为test.sh 第一行应该为#! /bin/bash 1.运行和调试的结果是不一样的 调试 sh -x test.sh 这时在计算两个数的和sum=$[$a+$b]时得到sum=3+4,而 ...
- 【Android测试】【随笔】性能采集工具——小松鼠诞生记
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/4945066.html 起因 去年刚加入TX的时候,我便接手 ...