<?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);
时间: 2024-10-10 08:24:28