php 图片加文字 图片生成图片水印
来源:互联网 发布:apache与php关系 编辑:程序博客网 时间:2024/06/05 03:21
<?php
class TupianController{
/*
* bgurl 背景url
* tuurl 图片url
* dingwei [x,y] 图片在背景图的xy 位置
* daxiao [w,h] 图片的大小
* pathfile 存储路径文件名
*/
public function Perweima($bgurl,$tuurl,$dingwei,$daxiao,$pathfile){
$base_name = $bgurl;
$e = $tuurl;
// Content type
header('Content-Type: image/jpeg');
// Load
$thumb = imagecreatefromjpeg($base_name);// 图片创建到jpeg
if(is_string($e)){
list($width, $height) = getimagesize($e);// 获取图片的大小等信息
if(strpos($e,'png')){
$e_p = imagecreatefrompng($e);// 图片创建到png
}
if(strpos($e,'jpg')){
$e_p = imagecreatefromjpeg($e);// 图片创建到jpg
}
}else{
$e_p = $tuurl;
}
// 图片复制
$is = imagecopyresized($thumb,$e_p,$dingwei[0],$dingwei[1], 0, 0,$daxiao[0],$daxiao[0],$width,$height);
imagejpeg($thumb,$pathfile);
imagedestroy($thumb);
}
/*
* 图片加文字
* str 添加文字
* dingwei 0 字体大小
1 选转的角度
2 字体x轴位置
3 字体y轴位置
* pathfile 背景图路径
* fontpath 字体路径
* savepathimg 图片存储路径
*/
public function shengc_pngimage_str($str,$dingwei,$pathfile,$fontpath,$savepathimg){
$block = imagecreatefromjpeg($pathfile);// 图片创建到jpeg
//拾取一个完全透明的颜色,不要用imagecolorallocate拾色
$color = imagecolorallocate($block,255,255,255);
//字体拾色
// imagealphablending($block , false);
//关闭混合模式,以便透明颜色能覆盖原画板
// imagefill($block , 0 , 0 , $bg);
//填充
// imagefttext($block,15,0,365,1043,$color,$fontpath,$text);
imagefttext($block,$dingwei[0],$dingwei[1],$dingwei[2],$dingwei[3], $color, $fontpath,$str);
// imagestring($block,25,365,1043,'',$color);
imagesavealpha($block , true);
//设置保存PNG时保留透明通道信息
header("content-type:image/png");
imagepng($block,$savepathimg);
//生成图片
imagedestroy($block);
}
}
$hecheng = new TupianController();
$pathfilesc = './bg1.jpg';
$hecheng->Perweima('./bg.jpg','./erweima.jpg',[295,1070],[160,160],$pathfilesc);
$hecheng->shengc_pngimage_str('XXX',[18,0,365,1042],$pathfilesc,'./msyh.ttf',$pathfilesc);
?>
class TupianController{
/*
* bgurl 背景url
* tuurl 图片url
* dingwei [x,y] 图片在背景图的xy 位置
* daxiao [w,h] 图片的大小
* pathfile 存储路径文件名
*/
public function Perweima($bgurl,$tuurl,$dingwei,$daxiao,$pathfile){
$base_name = $bgurl;
$e = $tuurl;
// Content type
header('Content-Type: image/jpeg');
// Load
$thumb = imagecreatefromjpeg($base_name);// 图片创建到jpeg
if(is_string($e)){
list($width, $height) = getimagesize($e);// 获取图片的大小等信息
if(strpos($e,'png')){
$e_p = imagecreatefrompng($e);// 图片创建到png
}
if(strpos($e,'jpg')){
$e_p = imagecreatefromjpeg($e);// 图片创建到jpg
}
}else{
$e_p = $tuurl;
}
// 图片复制
$is = imagecopyresized($thumb,$e_p,$dingwei[0],$dingwei[1], 0, 0,$daxiao[0],$daxiao[0],$width,$height);
imagejpeg($thumb,$pathfile);
imagedestroy($thumb);
}
/*
* 图片加文字
* str 添加文字
* dingwei 0 字体大小
1 选转的角度
2 字体x轴位置
3 字体y轴位置
* pathfile 背景图路径
* fontpath 字体路径
* savepathimg 图片存储路径
*/
public function shengc_pngimage_str($str,$dingwei,$pathfile,$fontpath,$savepathimg){
$block = imagecreatefromjpeg($pathfile);// 图片创建到jpeg
//拾取一个完全透明的颜色,不要用imagecolorallocate拾色
$color = imagecolorallocate($block,255,255,255);
//字体拾色
// imagealphablending($block , false);
//关闭混合模式,以便透明颜色能覆盖原画板
// imagefill($block , 0 , 0 , $bg);
//填充
// imagefttext($block,15,0,365,1043,$color,$fontpath,$text);
imagefttext($block,$dingwei[0],$dingwei[1],$dingwei[2],$dingwei[3], $color, $fontpath,$str);
// imagestring($block,25,365,1043,'',$color);
imagesavealpha($block , true);
//设置保存PNG时保留透明通道信息
header("content-type:image/png");
imagepng($block,$savepathimg);
//生成图片
imagedestroy($block);
}
}
$hecheng = new TupianController();
$pathfilesc = './bg1.jpg';
$hecheng->Perweima('./bg.jpg','./erweima.jpg',[295,1070],[160,160],$pathfilesc);
$hecheng->shengc_pngimage_str('XXX',[18,0,365,1042],$pathfilesc,'./msyh.ttf',$pathfilesc);
?>
阅读全文
0 0
- php 图片加文字 图片生成图片水印
- 生成缩略图,加文字水印,图片水印
- php生成图片文字水印
- php生成 文字水印 图片水印
- 图片加文字水印
- 图片加水印文字
- PHP给图片加文字水印和图片水印
- Itext PDF生成 加水印图片文字
- Itext PDF生成 加水印图片文字
- php给图片加文字水印
- PHP实现给图片加文字水印
- php图片加水印
- PHP水印图片文字
- php文字生成图片以及给图片加水印流程及代码详解
- PHP生成加水印的图片类
- php将文字写在图片上,图片加水印
- PHP 生成文字及图片水印
- php 图片水印 文字水印
- iOS HTTP, http协议, tcp, ip
- java Properties 键的顺序按照文件里的顺序排列
- 介绍下常见的直播协议
- 每周荐书:大数据、深度学习、架构(评论送书)
- Oracle:忘记配置密码
- php 图片加文字 图片生成图片水印
- android事件传递——1.概述
- 成为Java GC专家(3)—如何优化Java垃圾回收机制
- final, finally, finalize的区别
- NDK各版本下载
- 面试题:两个Activity之间如何传递参数?
- android权限大全
- 可滑动的viewpagerIndicator
- Android Studio 升级到 2.3.3