PHP合成图片、生成文字、居中对齐、画线、矩形、三角形、多边形、图片抗锯齿、不失真 高性能源码示例
来源:互联网 发布:中指数据库 编辑:程序博客网 时间:2024/05/20 07:14
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;//18号字体 $fontColor = imagecolorallocate ( $target, 255, 0, 0 );//字体的RGB颜色 $fontWidth = imagefontwidth ( $fontSize ); $fontHeight = imagefontheight ( $fontSize ); $textWidth = $fontWidth * mb_strlen ( $text1 ); $x = ceil ( ($width - $textWidth) / 2 );//计算文字的水平位置 // $textHeight = $fontHeight; // $y = ceil(($height - $textHeight) / 2);//计算文字的垂直位置 imagettftext ( $target, $fontSize, 0, $x, 190, $fontColor, $font, $text1 ); $textWidth = $fontWidth * mb_strlen ( $text2 ); $x = ceil ( ($width - $textWidth) / 2 ); imagettftext ( $target, $fontSize, 0, $x, 370, $fontColor, $font, $text2 ); $textWidth = $fontWidth * mb_strlen ( $text3 ); $x = ceil ( ($width - $textWidth) / 2 ); imagettftext ( $target, $fontSize, 0, $x, 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, 300, 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', '哈哈', '嘿嘿', '呵呵' );exit ();
0 0
- PHP合成图片、生成文字、居中对齐、画线、矩形、三角形、多边形、图片抗锯齿、不失真 高性能源码示例
- HTML5---Canvas-画线,空心图,矩形,文字,三角形,旋转图片
- 文字图片水平居中对齐
- css 图片 文字居中对齐
- php实现等比例生成图片缩略图不失真
- php 图片和文字合成图片技术
- (PHP)图片加文字和图片合成
- 画线,矩形,图片:
- 生成无失真不变形图片类
- web 开发笔记“图片文字居中对齐”
- 按钮图片和文字上下居中对齐
- css 图片文字居中对齐方案
- PHP 图片等比例缩放不失真
- 使用PHP实现生成固定大小图片缩略图功能(智能裁剪,图片不失真)
- 使用PHP实现生成固定大小图片缩略图功能(智能裁剪,图片不失真)
- 图片压缩不失真
- 不失真缩放图片
- ie6下li内图片和文字不居中对齐的解决办法
- 轻松百度搜索 智能搜索 云脉CC慧眼百度搜索版 OCR识别
- php.ini修改php上传文件大小限制
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- 產生隨機數
- 反射实现 AOP 动态代理模式(Spring AOP 的实现 原理)
- PHP合成图片、生成文字、居中对齐、画线、矩形、三角形、多边形、图片抗锯齿、不失真 高性能源码示例
- Python学习一:文件/目录操作合集
- OPENCV 图像翻转
- 【Java&Android开源库代码剖析】のandroid-smart-image-view
- 分花生游戏 (博弈论)
- rgb颜色转换(16进制->10进制)
- Phalcon 常用函数 方法
- OScache的安装与配置
- The CLR’s Execution Model