Automatically watermark all uploaded photos (给所有上传的相片加水印)

Hello,

This mod automatically watermark all uploaded photos.

Price: FREE, enjoy.

You will have to edit 3 files:

1. ../classes/image.class.php - watermark function.
2. ../modules/upload/photo.php - when upload photos from upload page.
3. ../modules/album/addphotos.php - when add photos to existing album.
---------------------------------------------

1. In "../classes/images.class.php" find (~ line 195):

	
public function watermark()
{
}


and replace with:


public function watermark($SourceFile, $WatermarkFile, $SaveToFile = NULL)
{
$watermark = @imagecreatefrompng($WatermarkFile)
or exit('Cannot open the watermark file.');
imageAlphaBlending($watermark, false);
imageSaveAlpha($watermark, true);
$image_string = @file_get_contents($SourceFile)
or exit('Cannot open image file.');
$image = @imagecreatefromstring($image_string)
or exit('Not a valid image format.');
$imageWidth=imageSX($image);
$imageHeight=imageSY($image);
$watermarkWidth=imageSX($watermark);
$watermarkHeight=imageSY($watermark);
$coordinate_X = ( $imageWidth - 5) - ( $watermarkWidth);
$coordinate_Y = ( $imageHeight - 5) - ( $watermarkHeight);
imagecopy($image, $watermark, $coordinate_X, $coordinate_Y, 0, 0, $watermarkWidth, $watermarkHeight);
if(!($SaveToFile)) header('Content-Type: image/jpeg');
imagejpeg ($image, $SaveToFile);
imagedestroy($image);
imagedestroy($watermark);
if(!($SaveToFile)) exit;
}




2. In "../modules/upload/photo.php" find (~ line 90):


$dst = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->process($src, $dst, 'MAX_WIDTH', 575, 0);
$image->resize(true, true);


and after "$image->resize(true, true);" insert this:


$image_location = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
// Locate the watermark file wherever you choose (remember PNG format). I put in ../media/photos/watermark.png
$watermark_location = $config['BASE_DIR']. '/media/photos/watermark.png';
$save_watermarked_file_to = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->watermark($image_location, $watermark_location, $save_watermarked_file_to);



3. In "../modules/album/addphotos.php" find (~ line 40):


$dst = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->process($src, $dst, 'MAX_WIDTH', 575, 0);
$image->resize(true, true);



and like the previous after "$image->resize(true, true);" insert this:


$image_location = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
// Locate the watermark file wherever you choose (remember PNG format). I put in ../media/photos/watermark.png
$watermark_location = $config['BASE_DIR']. '/media/photos/watermark.png';
$save_watermarked_file_to = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->watermark($image_location, $watermark_location, $save_watermarked_file_to);


!!! ++$photos; must be below the pasted code.

There is screens from thats files after mods.

image.class.php

 

1. ../classes/image.class.php - watermark function.
i did a copy

2. ../modules/upload/photo.php - when upload photos from upload page.


$image->process($src, $dst, 'MAX_WIDTH', 575, 0);
$image->resize(true, true);
$dst = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->process($src, $dst, 'MAX_WIDTH', 575, 0);
$image->resize(true, true);
$image_location = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
// Locate the watermark file wherever you choose (remember PNG format). I put in ../media/photos/watermark.png
$watermark_location = $config['BASE_DIR']. '/media/photos/watermark.png';
$save_watermarked_file_to = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->watermark($image_location, $watermark_location, $save_watermarked_file_to);




3. ../modules/album/addphotos.php - when add photos to existing album.


$image->process($src, $dst, 'MAX_WIDTH', 575, 0);
$image->resize(true, true);
$dst = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->process($src, $dst, 'MAX_WIDTH', 575, 0);
$image->resize(true, true);
$image_location = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
// Locate the watermark file wherever you choose (remember PNG format). I put in ../media/photos/watermark.png
$watermark_location = $config['BASE_DIR']. '/media/photos/watermark.png';
$save_watermarked_file_to = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->watermark($image_location, $watermark_location, $save_watermarked_file_to);

++$photos;


think somewhere there is error


$image->process($src, $dst, 'MAX_WIDTH', 575, 0);
$image->resize(true, true);
$dst = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->process($src, $dst, 'MAX_WIDTH', 575, 0);
$image->resize(true, true);


in my code not 2x "'MAX_WIDTH', 575, 0"

its looks like you added that to:


$dst = $config['BASE_DIR']. '/media/photos/' .$photo_id. '.jpg';
$image->process($src, $dst, 'MAX_WIDTH', 575, 0);
$image->resize(true, true);


but I was thinking to be pasted after that  

转载于:https://www.cnblogs.com/94YY/p/4896034.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值