准备工作:

 PHP给图片加文字(水印)

 

 

代码:

 

<?php
header("Content-type: image/jpeg");    //浏览器输出,如不需要可去掉此行
$im = @imagecreatefromjpeg('bg.jpg');    //从图片建立文件,此处以jpg文件格式为例
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$text = '16';  //要写到图上的文字
$font = 'arial.ttf';  //写的文字用到的字体。
$srcw=imagesx($im);
imagettftext($im, 40, 0, 20, 80, $grey, $font, $text);
imagettftext($im, 40, 0, 20, 80, $black, $font, $text);
imagettftext($im, 40, 0, 20, 80, $white, $font, $text);
imagepng($im);
imagedestroy($im);
?>

 

【效果】
PHP给图片加文字(水印)

 

 

如果要将图片保存到某个文件夹,只需将 :

imagepng($im);改为:

imagepng($im,"路径/output.png");

 

 

 

 

 

 

 

 

 

相关文章:

  • 2021-11-17
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2021-12-07
  • 2022-12-23
  • 2021-11-23
  • 2021-06-14
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案