为图像添加水印

时间:2013-04-30 14:27:50

标签: alfresco

我需要为添加到文件夹(空间)“Image in”的图像添加水印,并将图像移动到“图像输出”空间(通过内容规则)。

变压器(添加到c:\ Alfresco \ tomcat \ webapps \ alfresco \ WEB-INF \ classes \ com \ xyz \:

package com.xyz;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.Charset;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.alfresco.repo.content.transform.AbstractContentTransformer2;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: dragan
 */
public class ImageTransformer extends AbstractContentTransformer2 {
    private static final Log logger = LogFactory.getLog(ImageTransformer.class);

    static {
        logger.info("Created ImageTransformer");
    }

    protected void transformInternal(ContentReader contentReader, ContentWriter contentWriter, TransformationOptions transformationOptions) throws Exception {
        logger.info("transformInternal" );
        // put some water on the image
    }

    public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions transformationOptions) {
        logger.info("getReliability - sourceMimetype :" + sourceMimetype + " targetMimetype: " + targetMimetype );
        if (sourceMimetype.equals(MimetypeMap.MIMETYPE_IMAGE_JPEG)
                || sourceMimetype.equals(MimetypeMap.MIMETYPE_IMAGE_PNG)
                || sourceMimetype.equals(MimetypeMap.MIMETYPE_IMAGE_GIF) &&
                targetMimetype.equals(MimetypeMap.MIMETYPE_IMAGE_JPEG)) {
            return true;
        } else {
            return false;
        }
    }
}

根据http://docs.alfresco.com/3.4/index.jsp?topic=%2Fcom.alfresco.Enterprise_3_4_0.doc%2Ftasks%2Fcontenttrans-customize.html文件 content-services-context.xml被添加到c:\ Alfresco \ tomcat \ shared \ classes \ alfresco \ extension \

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
 ...
<!-- Content Transformations -->
   <bean id="transformer.XYZImages" class="com.xyz.ImageTransformer" parent="baseContentTransformer" >
   <property name="explicitTransformations">
         <list>
            <bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails" >
                <property name="sourceMimetype"><value>image/jpeg</value></property>
                <property name="targetMimetype"><value>image/jpeg</value></property>
            </bean>
            <bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails" >
                <property name="sourceMimetype"><value>image/png</value></property>
                <property name="targetMimetype"><value>image/jpeg</value></property>
            </bean>
            <bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails" >
                <property name="sourceMimetype"><value>image/gif</value></property>
                <property name="targetMimetype"><value>image/jpeg</value></property>
            </bean>
         </list>
      </property>
   </bean>
</beans>

重新启动Alfresco服务器时,没有log logger.info(“Created ImageTransformer”); 是否有可能实现这一过程?如何从内容规则调用图像转换器?

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用webscript而不是Java: https://code.google.com/p/alfresco-pdf-toolkit/