You can apply watermark on the image preview.
This is achieved by the modified workflow ..\config\global\gn4_tark4_common\wf_ CreateWatermarkPreview.xml (the code is available on the end of this topic).
The workflow uses TransformData activity with the step AddWatermark.
How it works?
1.Put in the appropriate folder (in this example it's c:\temp folder) the appropriate watermark imagel myWatermark.jpg (or change the path in the workflow wf_ CreateWatermarkPreview.xml)
2.Load wf_CreateWatermarkPreview.xml in the database by means of cmd4 config –in ..
3.Modify the wf_ImportActivityData.xml to call the new workflow wf_CreateWatermarkPreview.xml. Replace
<ExecuteSequentialWorkflow
x:Name="createImagePreview"
WorkflowName="createPreview"
Description="Creating image preview...">
with
<ExecuteSequentialWorkflow
x:Name="createImagePreview"
WorkflowName="createWatermarkPreview"
Description="Creating image preview...">
4.Load the modified file wf_ImportActivityData.xml in the database (cmd4 config –in ..)
5.Upload from the Web interface an image and check the result.
How to add watermark using parser.exe?
The command to add a watermark using the tool parser.exe is:
parser -in "c:\temp\myImage.jpg" -convert AddWatermark -p:int 1 -p:int 0 -p:int 80 -p:string "c:\temp\myWatermark.jpg" -p:string “TopRight”
On the myImage.jpg will be applied myWatermark.jpg image as watermark; position TopRight; the watermark will have inverted colors (first integer parameter), will be not fitted to original image (second integer parameter), with transparency level 80 (third integer parameter).
<?xml version="1.0" encoding="utf-8"?>
<!-- This workflow parses a specified data attribute of an object of a specified type, generates the preview form the parsed data attribute, and stores the preview generated into another data attribute of the same object.
It expects the following parameters: - objectId : numeric id of the object for which the preview must be generated - objectTypeName : name of the type of object for which the preview must be generated - sourceAttrName : name of the data attribute containing the source file to be parsed - destAttrName : name of the data attrinute into which the preview generated must be stored -->
<wfres:workFlow xmlns:wfres="http://www.teradp.com/schemas/GN4/1/WFRes.xsd" xmlns:inopt="http://www.teradp.com/schemas/GN4/1/XmlImportOptions.xsd" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:coll="clr-namespace:System.Collections;assembly=mscorlib">
<SequentialWorkflow x:Name="main" xmlns="http://www.teradp.com/schemas/GN4/1/Workflow/Activity" xmlns:common="http://www.teradp.com/schemas/GN4/1/Common" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wf="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
<!-- load the original data file from the database --> <LoadData x:Name="loadData" ObjectIds='{wf:ActivityBind main, Path=ParValueAsIds["objectId"]}' AttributeName='{wf:ActivityBind main, Path=ParValue["sourceAttrName"]}'>
<!--parse the original data in order to generate the preview--> <Parse x:Name="parse" Data="{wf:ActivityBind loadData, Path=DataOut}" Description="Parsing original file"> <Parse.Options> <common:ParseOptions ThumbnailSize="0" PreviewSize="400" PreviewQuality="80" UseAttributes="false" /> </Parse.Options>
<!--import the preview generated into the database--> <ImportXml x:Name="importPreview" XmlIn="{wf:ActivityBind parse, Path=XmlOut}"> <ImportXml.Pars> <wf:WorkflowParameterBinding wf:ParameterName="objectId" wf:Value='{wf:ActivityBind main, Path=ParValue["objectId"]}' /> <wf:WorkflowParameterBinding wf:ParameterName="objectTypeName" wf:Value='{wf:ActivityBind main, Path=ParValue["objectTypeName"]}' /> <wf:WorkflowParameterBinding wf:ParameterName="destAttrName" wf:Value='{wf:ActivityBind main, Path=ParValue["destAttrName"]}' /> </ImportXml.Pars> </ImportXml>
<!-- load the just created preview image --> <LoadData x:Name="loadPreview" ObjectIds='{wf:ActivityBind main, Path=ParValueAsIds["objectId"]}' AttributeName='{wf:ActivityBind main, Path=ParValue["destAttrName"]}'>
<!-- add the watermark to the preview --> <TransformData x:Name="addWatermark" Data="{wf:ActivityBind loadPreview, Path=DataOut}" Description="Add the watermark to the preview image">
<TransformData.Steps> <x:Array Type="{x:Type Step}"> <common:Step Conversion="AddWatermark"> <common:Step.Parameters> <coll:ArrayList> <!-- 1st integer parameter: inverted colors (1=inverted, 0=not inverted) --> <sys:Int32>1</sys:Int32> <!-- 2nd integer parameter: fit to image (1=fit, 0=don't fit) --> <sys:Int32>0</sys:Int32> <!-- 3nd integer parameter: transparency (alpha level: from 1 to 255=transparent) --> <sys:Int32>80</sys:Int32> <!-- 1st string parameter: path of the watermark image --> <sys:String>c:\temp\myWatermark.jpg</sys:String> <!-- 2nd string parameter: watermark position (TopLeft, TopRight, BottomRight, BottomLeft, Centered --> <sys:String>Centered</sys:String> </coll:ArrayList> </common:Step.Parameters> </common:Step> </x:Array> </TransformData.Steps>
</TransformData>
<!-- save the preview with watermark --> <StoreData x:Name="savePreview" ObjectIds='{wf:ActivityBind main, Path=ParValueAsIds["objectId"]}' AttributeName='{wf:ActivityBind main, Path=ParValue["destAttrName"]}' Data="{wf:ActivityBind addWatermark, Path=DataOut}" />
</LoadData> </Parse> </LoadData> </SequentialWorkflow>
<inopt:XmlImportOptions wfres:activityName="importPreview"> <inopt:Xslt> <xsl:stylesheet version="1.0" xmlns:fn="http://www.teradp.com/schemas/GN4/1/Xslt" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xapGImg="http://ns.adobe.com/xap/1.0/g/img/" xmlns:xmp="http://ns.adobe.com/xap/1.0/"> <xsl:param name="pars" /> <xsl:template match="//*"> <xsl:element name="{$pars/*/add[@key='objectTypeName']/@value}"> <xsl:attribute name="id"> <xsl:value-of select="fn:objectIdToString($pars/*/add[@key='objectId']/@value)"/> </xsl:attribute> <xsl:if test="count(//xmp:Thumbnails/rdf:ALT/rdf:li) > 0"> <xsl:element name="{$pars/*/add[@key='destAttrName']/@value}"> <xsl:attribute name="mime"> <xsl:text>image/</xsl:text> <xsl:value-of select="//xmp:Thumbnails/rdf:ALT/rdf:li[1]/*/xapGImg:format" /> </xsl:attribute> <xsl:element name="data"> <xsl:value-of select="//xmp:Thumbnails/rdf:ALT/rdf:li[1]/*/xapGImg:image" /> </xsl:element> </xsl:element> </xsl:if> </xsl:element> </xsl:template> </xsl:stylesheet> </inopt:Xslt> </inopt:XmlImportOptions>
</wfres:workFlow> |
You can apply a watermark on cropped, but not yet processed images.
See the Crop workflow with watermark for further instructions.
Note
You need a Tera Forum account to access to this content: require it on the support desk.