imageresizer.Plugins.Watermark on classic asp - asp-classic

I need to use this plugin to add watermarks to images using classic ASP. I had this work partially using this code:
dim o, b, wm, layer,textlayer
Set b = CreateObject("ImageResizer.Configuration.Config")
Set wm = CreateObject("ImageResizer.Plugins.Watermark.WatermarkPlugin")
Set textlayer = CreateObject("ImageResizer.Plugins.Watermark.TextLayer")
Set layer = CreateObject("ImageResizer.Plugins.Watermark.Layer")
textlayer.Text = "Yeees"
textlayer.fontSize = 50
layer.fill = True
set layer("dd") = textlayer 'THIS IS FAILING
wm.NamedWatermarks("sfdf") = layer("dd") 'THIS IS FAILING TOO
wm.Install(b)
b.BuildImage "C:\lg1_1361_44.jpg", "C:\lg1_1361_44_WATER.png", "watermark=tessst&format=png"

Why are you creating an instance of Layer? TextLayer and ImageLayer are the classes you want to work with
I would drop everything related to 'layer' and try this instead.
textLayer.fill = True
wm.NamedWatermarks("sfdf") = textLayer
You'll also need "watermark=sfdf" instead of "tessst"

Related

Add Button to Chart

I have a working Excel VBA macro called CreateGraph that generates an Excel chart from existing data. I want to modify CreateGraph such that after the chart is created it adds a button on the chart itself that in turn can be used to call CreateGraph again to make a new (updated) chart.
After much trial and error, google searches, and abundant use of the macro recorder I have cobbled together the following:
Sub AddButtonForNewChart()
Dim MyButton As Button
Set MyButton = ActiveChart.Buttons.Add(1002750, 138119.25, 589949.25, 238461.75)
With MyButton
.Visible = True
.OnAction = "MainRoutine"
.Select
With Selection
.Characters.Text = "Create New Chart"
.AutoScaleFont = False
With .Characters(Start:=1, Length:=9).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With
End With
End With
End Sub
This macro runs just fine .... except nothing is produced. No button anywhere.
Anyone have any thoughts?
Eurika! SMACK (the sound of palm hitting forehead). It turns out this routine WAS working all along. The length & width parameters for the Buttons.Add line were the culprit. They were part of the macro recorder generated effort, but for some unknown reason did not translate well. When replaced with more reasonable numbers ... viola ... everything worked. My working script now reads:
Sub AddButtonForNewChart()
Dim MyButton As Button
Set MyButton = ActiveChart.Buttons.Add(10, 10, 100, 25)
With MyButton
.Characters.Text = "Create New Chart"
.AutoScaleFont = False
.Visible = True
.OnAction = "MainRoutine"
End With
End Sub

VB.net aspX image resize and created file permission denied

I'm trying to create an image based on an original image as a template.
a picture > kapak.jpg - resize to 1366x768 > orta.jpg - resize to 848x480
Code is working. Nothing wrong BUT when I use; code block 2 its locking the file which is kapak.jpg
I can't delete or rename etc. Even if I close the browser or vstudio or all. Nothing changes but restart the iis. I even cant delete it on the file browser as well. It's just locking it and doesnt allow anything. it says that; w3wp.exe or iis express worker is using this file so you cant delete or etc. Access denied.
I tried dispose or =nothing for bitmap
moved code block 2 to another sub
nothing changed.
If I dont use code block 2 it creates and allows me to delete or rename etc.
Any suggestions will be appreciated. How can I set free the file?
button_1_click
gelenIMG.ImageUrl = "\dene_2.jpg"
Dim uzatBOYfark As Integer
Dim uzatENfark As Integer
Dim kapakRESIMayar As New Rectangle(0, 0, 1366, 768)
uzatENfark = kapakRESIMayar.Width : uzatBOYfark = kapakRESIMayar.Height
Using orijinalRESIM = Image.FromFile(Server.MapPath(gelenIMG.ImageUrl))
If orijinalRESIM.Width < kapakRESIMayar.Width Then uzatENfark = kapakRESIMayar.Width * (kapakRESIMayar.Width / orijinalRESIM.Width)
If orijinalRESIM.Height < kapakRESIMayar.Height Then uzatBOYfark = kapakRESIMayar.Height * (kapakRESIMayar.Height / orijinalRESIM.Height)
Using kapakZEMINsablon = New Bitmap(kapakRESIMayar.Width, kapakRESIMayar.Height)
Using grp = Graphics.FromImage(kapakZEMINsablon)
grp.Clear(Color.Red)
grp.DrawImage(orijinalRESIM, New Rectangle(0, 0, uzatENfark, uzatBOYfark + 1), kapakRESIMayar, GraphicsUnit.Pixel)
End Using
kapakZEMINsablon.Save(Server.MapPath(geciciRESIMyeri & "\kapak.jpg"), Imaging.ImageFormat.Jpeg)
End Using
End Using
imgKAPAK.ImageUrl = geciciRESIMyeri & "\kapak.jpg"
code block 2:
Dim bitmapORTA As New Bitmap(Image.FromFile(Server.MapPath(imgKAPAK.ImageUrl), True), 848, 480)
bitmapORTA.Save(Server.MapPath(geciciRESIMyeri & "\orta.jpg"), Imaging.ImageFormat.Jpeg)
imgORTA.ImageUrl = geciciRESIMyeri & "\orta.jpg"

Detect HTTP_USER_AGENT in asp

I need in an asp site, detect if the device used is a tablet.
i'd like to know which user agent is use for this one
for now i do this
agent = Request.ServerVariables("HTTP_USER_AGENT")
Set reg = New RegExp
With reg
.Pattern = "(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm)"
.IgnoreCase = True
.Global = True
End With
match = reg.Test(agent)
If match Then
session("IsMobileBrowser") = 1
Else
session("IsMobileBrowser") = 0
End If
Thanks
We are using this API to dectect mobile devices on our classic asp website and it works great.
https://code.google.com/p/mobileesp/source/browse/#svn/JavaScript
Use DetectTierTablet function to detect tablets.
Also with very few changes to the code we were able to include it server side. Just had to replace:
if (navigator && navigator.userAgent)
this.uagent = navigator.userAgent.toLowerCase();
with
if (Request.ServerVariables("HTTP_USER_AGENT").Item != null)
this.uagent = Request.ServerVariables("HTTP_USER_AGENT").Item.toLowerCase();

ASP.NET webcontrols render wrong in different culture settings

I have a self defined web control.
Some code in a loop:
double cellHeight = 12.34;
Label dcell = new Label();
dcell.Style["height"] = cellHeight + "pt";
dcell.Text = cellHeight;
If I use CultureInfo("cs-CZ")
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("cs-CZ");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("cs-CZ");
after render, the html came out
<span style="height:11,75pt">11,75</span>
actually what I expected is:
<span style="height:11.75pt">11,75</span>
height:11,75pt is totally wrong when rendered in browser, actually the browser does not consider 11,75pt as 11.75pt.
However I need to keep the text field displayed based on culture info: the text field displays 11,75 that is correct.
So this is the problem - how can I fix?
You need to convert double to string properly, for example:
dcell.Style["height"] = cellHeight.ToString("F", CultureInfo.CreateSpecificCulture("eu-ES")) + "pt";
Or like this:
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ".";
dcell.Style["height"] = cellHeight.ToString(nfi) + "pt";

Creating Dynamic Hotspots in an ASP.net imagemap

I need the ability to create a dynamic number of hotspots in an imagemap
the pseudo code for what I want to do is below:
Protected Sub AddHotSpot()
Dim r1 New RectangleHotSpot
For Each Item as datarow in dataset
r1.HotSpotMode = HotSpotMode.PostBack
r1.PostBackValue = "HotSpot 1"
r1.AlternateText = "HotSpot 1"
r1.Top = Item.Top
r1.Left = Item.Left
r1.Bottom = Item.Bottom
r1.Right = Item.Right
Next
think of r1 as some form of dynamic construct
Figured out how to perform this. I had to make the object above part of an array list then add each object to the array

Resources