该图像为PNG带有透明背景。图像实质是给某站点产品图上部添加打折信息的图标。由于ie系列浏览器无css旋转,遂用php将打折后文字写至图片上。

PHP根据PNG图像生成新图并添加文字

 

原图:

PHP根据PNG图像生成新图并添加文字

 

处理详细代码:

header("Content-type: image/png");
$discount= 60;//此处省略获取该数值途径
$font_path = 'arial.ttf';//字体文件的路径
$oldimage_name = 'off.png';//原始图片路径
$image_src = imagecreatefrompng($oldimage_name); //根据原始图片创建新图
imagesavealpha($image_src,true);//至关重要:保留原图alpha通道,否则png透明部分会被添黑
$color = imagecolorallocate($image_src, 255, 255, 255);//字体颜色
imagettftext($image_src, 16, -45, 15, 10, $color, $font_path, $discount);//将文字以16号字-45度角绘制到15,10坐标点
imagepng($image_src);

 

相关文章:

  • 2021-11-01
  • 2022-12-23
  • 2021-12-04
  • 2021-12-02
  • 2021-06-12
  • 2022-01-10
  • 2021-06-10
猜你喜欢
  • 2021-12-13
  • 2022-02-19
  • 2021-08-23
  • 2021-04-10
  • 2021-12-03
  • 2022-12-23
  • 2021-11-01
相关资源
相似解决方案