PHP中的动态水印
我用这个脚本在一个客户的网站上创建水印问题是一个水印适用于一个图像而不适用于另一个 肖像画 景观 以下是脚本:PHP中的动态水印,php,dynamic,watermark,Php,Dynamic,Watermark,我用这个脚本在一个客户的网站上创建水印问题是一个水印适用于一个图像而不适用于另一个 肖像画 景观 以下是脚本: <?php // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly transparent gif image with the watermark - goes in
<?php
// this script creates a watermarked image from an image file - can be a .jpg .gif or .png file
// where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory asthis script
// where this script is named watermark.php
// call this script with an image tag
// <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg
$imagesource = $_GET['path'];
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif") $image = @imagecreatefromgif($imagesource);
if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource);
if($filetype == ".png") $image = @imagecreatefrompng($imagesource);
if (!$image) die();
//This bit is the dynamic bit
if(imagesx($image) <=1100){
$watermark = @imagecreatefromgif('watermark_port.gif');
}elseif(imagesx($image) <=1600 && $imagewidth >1100){
$watermark = @imagecreatefromgif('watermark_lans.gif');
}elseif(imagesx($image) >1600){
$watermark = @imagecreatefromgif('watermark_lans.gif');
};
//End of dynamic code
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth)/2);
$startheight = (($imageheight - $watermarkheight)/2);
imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth,
$watermarkheight);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>
但是,动态水印不起作用。我想要的是,如果图像的宽度低于1100px,那么它使用纵向版本,如果超过这个宽度,则使用横向版本
任何想法都将受到极大的赞赏
谢谢
David您的“动态部分”所做的基本概括如下:
if something
do A
else if something
do B
else
do B
中间的那个完全是多余的
您需要的只是:
$watermark =
imagecreatefromgif("watermark_".(imagesx($image) <= 1100 ? "port" : "lans").".gif");
$watermark=
imagecreatefromgif(“水印”)