zoukankan      html  css  js  c++  java
  • 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 :) 

  • 相关阅读:
    hdu 2602 Bone Collector 01背包
    总结
    类--接口 抽象父类 多态 鸭子类型 格式化方法与析构方法 反射 异常处理 自定义异常 断言
    类--组合 继承 super关键字 面向对象的三大性
    面向对象 名称空间 类与对象
    re正则模块 垃圾回收机制
    常用模块--hashlib hmac:加密 xml xlrd xlwt:excel读|写 configparser subprocess
    常用模块-- random shutil shevle logging sys.stdin/out/err
    常用模块-- time os sys 递归 序列化

  • 原文地址:https://www.cnblogs.com/94YY/p/4896034.html
Copyright © 2011-2022 走看看