zoukankan      html  css  js  c++  java
  • watermark实现


    很多网站需要在上传的图片上面打水印。


    通常在配置apache之前,可以使用ImageMagic的命令工具composite来测试水印的效果,composite主要用于overlap one image over another.
    composite -gravity SouthEast -geometry '+5+5' watermark-small.png  t3.png  t31.png
    composite -gravity SouthEast -geometry '+10+10' watermark.png  \( t1.png -resize '550x450<' \) t11.png

     apache配置:使用ext_filter module调用ImageMagic包里面的composite命令对响应的图片加水印,类似下面的流程图。


    <IfModule mod_ext_filter.c>
    ##        ExtFilterDefine watermark mode=output intype=image/jpeg cmd="/usr/bin/composite -gravity SouthEast -geometry '+8+8' /home/media/watermark.gif - -"
            ExtFilterDefine watermark mode=output intype=image/jpeg cmd="/usr/bin/composite -gravity SouthEast -geometry '+8+8' /home/media/watermark.gif \( - -resize '550x450<' \) -"
            ExtFilterDefine watermark-small mode=output intype=image/jpeg cmd="/usr/bin/composite -gravity SouthEast -geometry '+4+4' /home/media/watermark-small.gif - -"
    </IfModule>

    <Location ~ "/.*photo-s">
            SetOutputFilter watermark
    </Location>

    <Location ~ "/.*photo-f">
            SetOutputFilter watermark-small
    </Location>

    <Location ~ "/.*photo-l">
            SetOutputFilter watermark-small
    </Location>

     注意
    1.ExtFilterDefine中最后的- - 分别表示输入与输出的图片。通常我们在测试的时候,是需要指定这个文件的。比如源文件是一个表达式,表示将t1.png文件放大后的文件做为源文件:  \( t1.png -resize '550x450<' \), t11.png表示生成的目标文件。
    2.规范命名上传文件的路径。使用正则式匹配大小图片的路径并使用不同的Filter处理。

    3.mode=output 表示mod_ext_filter处理的是输出的内容,也仅支持这一种模式。  intype=image/jpeg表示处理的内容类型须是图片。
    4.mod_ext_filter定义及使用场合
    At the most basic level, mod_ext_filter is simply a way to run content through an external program before it is outputted to the client. Think of it as a filter sitting between Apache and the user’s web browser.
    However, practically speaking, it would be horribly inefficent and probably too slow to be usable.

        •    Dynamically add a copyright footer, even on plain ‘ole static HTML pages. (Though mod_include would be better for this unless you’re doing something tricky that requires the extra logic of an external program. I’ll be covering this in an upcoming blog entry.)
        •    A profanity filter that can easily be used with any blog or messageboard software.
        •    Dynamically adding a watermark to images using “composite” (Step-by-step HOWTO).
        •    And my favorite… Automatically add a wrapper around external links for tracking purposes. This could be done by piping the output through search-and-replace regex using Perl, sed, or awk. This is great when used with a CMS and end-users will be self-publishing content, possibly adding their own links.

    参考

    http://www.rightbrainnetworks.com/blog/using-apaches-mod_ext_filter-to-automatically-add-watermarks-to-website-images/

     

    http://tda7088.blog.163.com/blog/static/294411542009112033151468/

  • 相关阅读:
    [转发]深入理解git,从研究git目录开始
    iOS系统网络抓包方法
    charles抓包工具
    iOS多线程中performSelector: 和dispatch_time的不同
    IOS Core Animation Advanced Techniques的学习笔记(五)
    IOS Core Animation Advanced Techniques的学习笔记(四)
    IOS Core Animation Advanced Techniques的学习笔记(三)
    IOS Core Animation Advanced Techniques的学习笔记(二)
    IOS Core Animation Advanced Techniques的学习笔记(一)
    VirtualBox复制CentOS后提示Device eth0 does not seem to be present的解决方法
  • 原文地址:https://www.cnblogs.com/highriver/p/2367165.html
Copyright © 2011-2022 走看看