[英]Watermark fading with transparent background
Have some script that display images on page with png watermark, but when i want to fade watermark png image to 50% there is white background display (but watermark fading to 50%) and when i want to change the size of watermark image the watermark png just gone and not displayed.有一些脚本在页面上显示带有 png 水印的图像,但是当我想将水印 png 图像淡化到 50% 时,会有白色背景显示(但水印淡化到 50%),当我想更改水印图像的大小时,水印png 刚刚消失并没有显示。 Please help me to solve my problemwith fading and size changing.
请帮助我解决褪色和尺寸变化的问题。 Ертл you to all.
Ертл 你给大家。
<?php
/* Image source */
$src = strtolower($_GET['src']);
/* If no image src redirect to start page */
if(isset($src) && !empty($src) && $src !=0 && $src !=1) {
header('content-type: image/jpeg');
$path = pathinfo($src);
$watermark = imagecreatefrompng('karantino.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
if ($path["extension"]=="png") {
$image = "no_img.jpg";
}else if ($path["extension"] == "jpg" || $path["extension"] == "jpeg"){
$image = imagecreatefromjpeg($src);
$size = getimagesize($src);
$dest_x = $size[0] - $watermark_width-10;
$dest_y = $size[1] - $watermark_height-10;
$alpha_channel = imagecolorallocatealpha($image, 255, 255, 255, 127);
imagecolortransparent($image, $alpha_channel);
imagefill($image, 0, 0, $alpha_channel);
imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
imagesavealpha($image);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
}
} else{
header("HTTP/1.1 301 Moved Permanently");
header ("Location: /");
}
/*
to use this code, just create php file with random name (i use wt.php) and put code like this in your HTML page <img src="wt.php?src=your_jpg_file.jpg">
*/
?>
Try to change image type to png (not the watermark image).尝试将图像类型更改为 png(不是水印图像)。 Because the default background in jpg is white.
因为 jpg 中的默认背景是白色的。 And about the size: change the image original size not in code.
关于尺寸:更改图像原始尺寸不在代码中。
I find a new working suggestion for me:我为我找到了一个新的工作建议:
<?php
header("Content-type:image/jpeg");
$src = $_GET["src"];
/* If no image src redirect to start page, else do watermark */
if(isset($src) && !empty($src) && $src!=0 && preg_match("/.(jpg|jpeg|png)$/", $src)){
$path = pathinfo($src);
if ($path["extension"] == "png") {
$stamp = imagecreatefrompng("../../favicon.png");
$im = imagecreatefrompng($src);
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right,
imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp),
imagesy($stamp));
imagepng($im);
imagedestroy($im);
}
else if ($path["extension"] == "jpg" || $path["extension"] == "jpeg"){
$stamp = imagecreatefrompng("../../favicon.png");
$im = imagecreatefromjpeg($src);
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right,
imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp),
imagesy($stamp));
imagepng($im);
imagedestroy($im);
}
else{
/* If unknow format */
$im = imagecreatefrompng("../important/no-photo.png");
imagepng($im);
imagedestroy($im);
}
}
else{
/* Redirect to start page if no string */
header("HTTP/1.1 301 Moved Permanently");
header ("Location: /");
}
/*
to use this code, just create php file with random name and put code like this in your HTML page <img src="wt.php?src=your_jpg_file.jpg">
*/
?>
But still have a problem.但是还是有问题。 When i use code like this
<img src="wt.php?src=/img/my_img/your_jpg_file.jpg">
instead of this <img src="wt.php?src=your_jpg_file.jpg">
the script didn't display any image.当我使用像这样的代码
<img src="wt.php?src=/img/my_img/your_jpg_file.jpg">
而不是这个<img src="wt.php?src=your_jpg_file.jpg">
脚本没有t 显示任何图像。
Any ideas?
有任何想法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.