在图片上加字符-base64转图片-图片转base64

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>get chinaz info</title>

<link rel="stylesheet" type="text/css" href="/img/css/admin.css" />
<script type="text/javascript" src="/img/js/jquery-1.4.2.min.js"></script>
</head>
<body>

</form>
<!-- <img src="https://img-blog.csdnimg.cn/2022010616404780876.jpeg">

<?php 
$base64_image_content = "https://img-blog.csdnimg.cn/2022010616404780876.jpeg";

$name = date('Y-m-d H:i:s',time());
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)){
$type = $result[2]; 
$new_file = "test.{$type}"; 
if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)))){ 
echo '新文件保存成功:', $new_file; 
}
}

 

 

 


$dst_path = 'test.jpg';
//创建图片的实例
$dst = imagecreatefromjpeg($dst_path);
//打上文字
$font = 'simsun.ttc';//字体
$red = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$black = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字体颜色
imagefttext($dst, 20, 0, 5, 50, $black, $font, '1');
imagefttext($dst, 20, 0, 85, 50, $black, $font, '2');
imagefttext($dst, 20, 0, 155, 50, $black, $font, '3');
imagefttext($dst, 20, 0, 225, 50, $black, $font, '4');
imagefttext($dst, 20, 0, 5, 130, $black, $font, '5');
imagefttext($dst, 20, 0, 85, 130, $black, $font, '6');
imagefttext($dst, 20, 0, 155, 130, $black, $font, '7');
imagefttext($dst, 20, 0, 225, 130, $black, $font, '8');
imagejpeg($dst,'3.jpg');
//输出图片
//list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
//switch ($dst_type) {
// case 1://GIF
// header('Content-Type: image/gif');
// imagegif($dst);
// break;
// case 2://JPG
// header('Content-Type: image/jpeg');
// imagejpeg($dst);
// break;
// case 3://PNG
// header('Content-Type: image/png');
// imagepng($dst);
// break;
// default:
// break;
//}
imagedestroy($dst);
?>

 


</body>
</html>

  

转载于:https://www.cnblogs.com/yixianyixian/p/4342386.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值