THINKPHP图片处理之图片合成,分享海报合成

https://book.employleague.cn/

package topthink/think-image

composer require topthink/think-image
Thinkphp5.0 ~ thinkphp6.0都可以用

使用方式

打开图片

	use think/Image;
	
	...

	$handler = Image::open($path); // $path 本地图片路径

打开网络图片

	private function download_remote_pic($url){
        $header = [
            'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
            'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
            'Accept-Encoding: gzip, deflate',
        ];
        $curl = curl_init();
        curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
        curl_setopt($curl,CURLOPT_HEADER,0);
        curl_setopt($curl,CURLOPT_NOBODY,0);
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl,CURLOPT_URL,$url);
        $output= curl_exec($curl);
        curl_close($curl);
        return $output;
    }
	$imageFile = $this->download_remote_pic('https://微信头像地址');
	file_put_content($path, $imageFile); // $path 图片路径
	$handler = Image::open($path);

图片合成

	$local = [100, 100];
	$handler->water($path, $local); // $path 图片本地路径  $local 数组 [$x, $y];

文字添加

	$handler->text($txt, $font, $size, $color, $local); 
	'$txt 是需要添加的文字  $font 字体文件 中文建议将C盘windows/Font下的楷体文件移动到项目目录下引用'
	'$size number类型 字体大小  单位px  $color 颜色 $local 同图片一样可以传入图片'

图片保存

 $handler->save($path); //$path文件路径
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值