Jul 9, 2007

Posted by in Tech Tips | 0 Comments

Image manipulation made simple?!

Problem summary:
A user needs to be able to scan in signatures and upload them to web site that has very strict input criteria:

  • 300 DPI
  • No larger than 600 * 150 pixels
  • Monochrome BMP file

Solution:
Having had a little bit to do with vbscript and hta files in the past I set about seeing if there was a command line image manipulator available. After a bit of searching I found that imagemagick had complied versions for windows (I previously thought it was just for linux servers) and not only that it worked for windows but was capable of being called directly with vbscript!
With a little bit of help from the script center guys I’d nocked up a simple hta that would allow you to specify multiple files using a standard windows selection box and then convert all the files to the correct format using imagemagick.
The code is included here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<head>
<title>Ben’s Magic Signature Resize</title>
<HTA:APPLICATION 
     ID="objTestHTA"
     APPLICATIONNAME="Signature resize"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>
 
 
 
<SCRIPT Language="VBScript">
 
 
 
 
‘To run this script you will need ImageMagick installed with VBscript extensions.
‘http://www.imagemagick.org/script/index.php
 
 
 
 
On Error Resume Next
set objShell = CreateObject( "WScript.Shell" )
MyDocuments = objShell.ExpandEnvironmentStrings("USERPROFILE")
 
 
 
 
Sub LoadInputImages Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "BMP|*.bmp|All Files|*.*" objDialog.FilterIndex = 1 objDialog.InitialDir = MyDocuments & "\My Documents" intResult = objDialog.ShowOpen
 
 
    If intResult = 0 Then
        Exit Sub
    End If
 
 
 
filename = objDialog.FileName
Set objOption = Document.createElement("OPTION") objOption.Text = filename objOption.Value = filename
Images.Add(objOption)
End Sub
 
 
 
 
Sub RunConvertion
Set fso = CreateObject("Scripting.FileSystemObject") Set img = CreateObject("ImageMagickObject.MagickImage.1")
 
 
 
 
For Each objItem in Images.Options inputfile = ObjItem.Value outputfile = left(inputfile, (len(inputfile)-4)) & "_converted.bmp" go = img.Convert("-resize","600×150","-density","118×118","-monochrome",inputfile,outputfile) Next
End Sub
</SCRIPT>
 
 
 
 
<body bgcolor="buttonface">
<input id=runbutton class="button" type="button" value="Add Image"
name="run_button" onClick="LoadInputImages"><p>
<select size="10" name="Images" style="width:300" >
</select>
<p>
<input id=convertbutton class="button" type="button" value="Convert"
name="convertbutton" onClick="RunConvertion">
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *