99388514

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
<?php
if (function_exists('imagepng')) {
    dir('GD库不存在');
}

//图片路径
$imagePath = './img/a.jpg';
//获取文件类型
$imageInfo = getimagesize($imagePath);
$imageExtension = image_type_to_extension($imageInfo[2], false);
//获取图片
$func = 'imagecreatefrom' . $imageExtension;
$image = $func($imagePath);
//水印字体
$font = './img/msyh.ttf';
//水印文字
$content = '新浪网';
//水印颜色
$color = imagecolorallocatealpha($image, 255, 255, 255, 30);
//添加水印
imagettftext($image, 12, 0, 10, 22, $color, $font, $content);
//输出图片
header('Content-Type:' . $imageInfo['mime']);
$func = 'image' . $imageExtension;
$func($image, null, 100);
//销毁图片
imagedestroy($image);

  

posted on 2016-05-29 11:03  PHP狗  阅读(2476)  评论(0编辑  收藏  举报