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 :) 

posted @   星星的学习小志  阅读(319)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示