码迷,mamicode.com
首页 > Web开发 > 详细

PHP给图片加文字(水印)

时间:2016-10-28 20:22:47      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:output   header   img   src   tput   建立   text   ack   head   

准备工作:

 技术分享

 

 

代码:

 

<?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);
?>

 

【效果】
技术分享

 

 

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

imagepng($im);改为:

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

 

 

 

 

 

 

 

 

 

PHP给图片加文字(水印)

标签:output   header   img   src   tput   建立   text   ack   head   

原文地址:http://www.cnblogs.com/renxing123/p/6008887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!