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

  • 相关阅读:
    【转载】Allegro Auto Rename器件反标注教程
    FPGA代码设计规范整理
    Cadence Allegro导网表的错误问题解决
    简单玩转Excel排序、筛选、分类汇总与数据透视表功能!
    zt一篇教会你写90%的shell脚本
    zt一篇教会你写90%的shell脚本
    TCP协议理解
    zt 改进TCP,阿里提出高速云网络拥塞控制协议HPCC
    zt TCP的困境与解决方案
    ztGoogle's BBR拥塞控制算法如何对抗丢包
  • 原文地址:https://www.cnblogs.com/94YY/p/4896034.html
Copyright © 2020-2023  润新知