PHP 用PHP的图像水印
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 用PHP的图像水印相关的知识,希望对你有一定的参考价值。
<?php
$main_img = "image.jpg"; // main big photo / picture
$watermark_img = "watermark.gif"; // use GIF or PNG, JPEG has no tranparency support
$padding = 3; // distance to border in pixels for watermark image
$opacity = 100; // image opacity for transparent watermark
$watermark = imagecreatefromgif($watermark_img); // create watermark
$image = imagecreatefromjpeg($main_img); // create main graphic
if(!$image || !$watermark) die("Error: main image or watermark could not be loaded!");
$watermark_size = getimagesize($watermark_img);
$watermark_width = $watermark_size[0];
$watermark_height = $watermark_size[1];
$image_size = getimagesize($main_img);
$dest_x = $image_size[0] - $watermark_width - $padding;
$dest_y = $image_size[1] - $watermark_height - $padding;
// copy watermark on main image
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $opacity);
// print image to screen
header("content-type: image/jpeg");
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
以上是关于PHP 用PHP的图像水印的主要内容,如果未能解决你的问题,请参考以下文章
php基础 gd图像生成缩放logo水印和验证码
php基础 gd图像生成缩放logo水印和验证码
用 PHP 合并两个图像
php中的图像水印
PHP php动态图像水印
如何使用 PHP 和 GD 制作水印图像,如 envato photodune 预览图像?