SIP ASP Watermark based on image orientation
SIP Watermark based on image orientation
Question:
How can I add different watermarks based on the orientation of a specific image using Smart Image Processor ASP??
Answer:
Sometimes it might be convenient to add different watermarks for either Landscape images or Portrait images. A simple adjustment in the Smart Image Processor ASP code can make this happen.This adjustment also enables different resizing settings for Landscape or Portrait images.
Note: This FAQ is based on a previous FAQ named SIP ASP Resize based on image orientation.
First create an upload form and apply the Pure ASP Upload and the Smart Image Processor to that form. Then switch to Code View and find the code for the Smart Image Processor.
<%
' Smart Image Processor 2.5.4
Dim sip1
Set sip1 = New ImageProcessor
sip1.Key = "EC6008C7-FDA9-4B89-B989-33A23B4CBA6A"
sip1.ScriptFolder = "ScriptLibrary"
sip1.Component = "Auto"
sip1.Source = "upload"
sip1.AutoOrient = false
sip1.KeepMetaData = false
sip1.Matte = "#FFFFFF"
sip1.UploadFields = "myfileField"
sip1.GetFiles
While sip1.HasFiles
sip1.LoadFromSource
sip1.Resize 1024, 768, true
sip1.AddWatermark "mywatermark.png", "Center-Center", false, "#000000", "50"
sip1.Overwrite = true
sip1.SaveJPEG 80
sip1.MoveNext
Wend
Set sip1 = Nothing
%>
Note: in this example sip1 was used as the name for the Smart Image Processor. This can be different in your own situation.
Find the code that begins with sip1.LoadFromSource. Enter the following code below this line.
' this is the if else checking if height is bigger then width
If pau.Fields("myfileField").Height > pau.Fields("myfileField").Width Then
sip1.Resize 768, 1024, true
sip1.AddWatermark "MyPortraitWatermarkImage.png", "Center-Center", false, "#66ff00", "50"
' this is the elseif checking if width is bigger then height
ElseIf pau.Fields("myfileField").Width > pau.Fields("myfileField").Height Then
sip1.Resize 1024, 768, true
sip1.AddWatermark "MyLandscapeWatermarkImage.png", "Center-Center", false, "#66ff00", "50"
End If
Note: the parts in red do not need to be entered. They are just placed there to clarify the code.
Your complete code will look somewhat like this, depending on your individual settings.
<%
' Smart Image Processor 2.5.4
Dim sip1
Set sip1 = New ImageProcessor
sip1.Key = "EC6008C7-FDA9-4B89-B989-33A23B4CBA6A"
sip1.ScriptFolder = "ScriptLibrary"
sip1.Component = "Auto"
sip1.Source = "upload"
sip1.AutoOrient = false
sip1.KeepMetaData = false
sip1.Matte = "#FFFFFF"
sip1.UploadFields = "myfileField"
sip1.GetFiles
While sip1.HasFiles
sip1.LoadFromSource
' this is the if else checking if height is bigger then width
If pau.Fields("myfileField").Height > pau.Fields("myfileField").Width Then
sip1.Resize 768, 1024, true
sip1.AddWatermark "MyPortraitWatermarkImage.png", "Center-Center", false, "#66ff00", "50"
' this is the elseif checking if width is bigger then height
ElseIf pau.Fields("myfileField").Width > pau.Fields("myfileField").Height Then
sip_testing.Resize 1024, 768, true
sip1.AddWatermark "MyLandscapeWatermarkImage.png", "Center-Center", false, "#66ff00", "50"
End If
sip1.Overwrite = false
sip1.Mask = "##path##large_##name##.jpg"
sip1.SaveJPEG 75
sip1.MoveNext
Wend
Set sip1 = Nothing
%>
Comments
Be the first to write a comment
You must me logged in to write a comment.