php 图片加文字加图片实现盖章,证书

具体实现代码请查看码云仓库

居中显示,定位显示,文字加粗,字体间距,

php图片加文字加logo: 实现文字加图片,加文字,从而实现工作中盖章,证书等的生成

注意点:linux服务器,需要把字体的后缀ttf 改为统一的 要么全大写,要么全小写

//统计中文字数
$user = '张三';
echo mb_strlen($user,'utf-8'); // 2
echo mb_strlen($user,'gb2312'); // 4

/**
*统计纯中文文字字数,此前搜索了好多,大多不好使,本方法统计不准确,不如直接使用mb_strlen
*/
function ccChinaStrLen($string){
      $j = 0; 
		for($i=1;$i <strlen($string);$i++) 
		{ 
			if(ord(substr($string,$i,1))> 0xa0){
				$j++;
				$i++;			
			}	
		}
		return $j;
}
    /**
	* 设置字体间距,支持中文无乱码
	*/
	function imagettftextSp_bak($image, $size, $angle, $x, $y, $color, $font, $text, $spacing = 0){
		if ($spacing == 0){
			imagettftext($image, $size, $angle, $x, $y, $color, $font, $text);
		}else{
		
            for ($i = 0; $i <strlen($text); $i++){ 
				$arr = imagettftext ($image, $size,0, $x, $y, $color, $font, mb_substr($text,$i,1)); 
				$x = $arr[4]+$spacing; 
			}  
		}

	}

function getBBoxW($bBox){
	  return $bBox[2] - $bBox[0];
}

//设置字体间距不支持中文,有乱码
function imagettftextSp($image, $size,$angle, $x, $y, $color, $font, $text, $spacing = 0)
	{
		$testStr = 'test';
		$testW   = $this->getBBoxW(imagettfbbox($size, 0, $font, $testStr));
		//$tool = mb_str_split($text);
		foreach (str_split($text) as $char){
			$fullBox = imagettfbbox($size, 0, $font, $char . $testStr);
			imagettftext($image, $size, $angle, $x - $fullBox[0], $y, $color, $font, $char);
			$x += $spacing + $this->getBBoxW($fullBox) - $testW;
		}
	}

处理RGB图片转为CMYK图片

 //将RGB图片转为CMYK图片
	public function imageRgbToCmyk($filePath){
      $img = new \Imagick($filePath);
      $img->setImageColorSpace(Imagick::COLORSPACE_CMYK);
      $icc_rgb = file_get_contents(dirname(__FILE__).'/common/static/plugin/sRGB_v4_ICC_preference.icc'); 
      $img->profileImage('icc', $icc_rgb); 
      $img->negateImage(FALSE, Imagick::COLOR_CYAN);
      $img->negateImage(FALSE, Imagick::COLOR_MAGENTA);
      $img->negateImage(FALSE, Imagick::COLOR_YELLOW);
      $img->negateImage(FALSE, Imagick::COLOR_BLACK);
      unset($icc_rgb); 
      $img->stripImage();
     
      $img->writeImage($filePath);
  }

sRGB_v4_ICC_preference.icc  在码云库中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱酥网络

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值