ShawnAdministrator
(KiX Supporter)
2008-03-12 04:29 AM
Easy123 Business Card Maker

Here is a quicky example script for loading an image, drawing on the image, than saving the image back to a file.

Easy123 Business Card Maker

Requires the latest and greatest Kixforms.Net

Download the script and template from here

The screenshot:



The code:

 Code:
Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form()
$Form.Text = "Easy123 Business Card Maker"
$Form.ClientWidth = 640
$Form.ClientHeight = 300
$Form.FontSize = 10

$PictureBox = $Form.Controls.Add($System.PictureBox())
$PictureBox.BackColor = $System.Color.AppWorkspace
$PictureBox.Dock = $System.DockStyle_Fill
$PictureBox.BorderStyle = $System.BorderStyle_Fixed3D

$Splitter = $Form.Controls.Add($System.Splitter())
$Splitter.Dock = $System.DockStyle_Left

$Panel = $Form.Controls.Add($System.Panel())
$Panel.Dock = $System.DockStyle_Left

$OpenButton = $Panel.Controls.Add($System.Button())
$OpenButton.Left = 10
$OpenButton.Top = 5
$OpenButton.Width = 150
$OpenButton.Text = "1) Open a template..."
$OpenButton.TextAlign = $System.ContentAlignment_MiddleLeft
$OpenButton.Enabled = 1
$OpenButton.Click = "OpenButton_Click($$System.Sender, $$System.EventArgs)"

$GoButton = $Panel.Controls.Add($System.Button())
$GoButton.Left = 10
$GoButton.Top = $OpenButton.Bottom + 5
$GoButton.Width = 150
$GoButton.Text = "2) Make my card --->"
$GoButton.TextAlign = $System.ContentAlignment_MiddleLeft
$GoButton.Enabled = 0
$GoButton.Click = "GoButton_Click($$System.Sender, $$System.EventArgs)"

$TextBox = $Panel.Controls.Add($System.TextBox())
$TextBox.MultiLine = 1
$TextBox.Left = 10
$TextBox.Top = $GoButton.Bottom + 5
$TextBox.Width = $Panel.ClientWidth - $TextBox.Left - 5
$TextBox.Height = 150
$TextBox.Enabled = 0

$SaveButton = $Panel.Controls.Add($System.Button())
$SaveButton.Left = 10
$SaveButton.Top = $TextBox.Bottom + 5
$SaveButton.Width = 150
$SaveButton.Text = "3) Save my card..."
$SaveButton.TextAlign = $System.ContentAlignment_MiddleLeft
$SaveButton.Enabled = 0
$SaveButton.Click = "SaveButton_Click($$System.Sender, $$System.EventArgs)"

$OpenFileDialog = $System.OpenFileDialog()
$OpenFileDialog.InitialDirectory = @SCRIPTDIR
$OpenFileDialog.Filter = "Templates (*.crd)|*.crd|All Files (*.*)|*.*"

$SaveFileDialog = $System.SaveFileDialog()
$SaveFileDialog.Filter = "Images (*.jpg)|*.jpg|All Files (*.*)|*.*"
$SaveFileDialog.InitialDirectory = @CURDIR

$Form.Center
$Form.Show

$TextBox.Anchor = 1+4+8

While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function OpenButton_Click($sender, $e)

 If $OpenFileDialog.ShowDialog <> $System.DialogResult_Ok
  Return
 Endif

 $Filename = $OpenFileDialog.FileName

 $BaseImage = $System.Bitmap.FromFile($Filename)

 $PictureBox.Image = $BaseImage

 $TextBox.Text = ""
 $TextBox.Text = $TextBox.Text + "John Doe" + @CRLF
 $TextBox.Text = $TextBox.Text + "Burbank Town Center" + @CRLF
 $TextBox.Text = $TextBox.Text + "201 East Magnolia, Suite 151" + @CRLF
 $TextBox.Text = $TextBox.Text + "Burbank, California  91502" + @CRLF
 $TextBox.Text = $TextBox.Text + "(818) 566-8556" + @CRLF

 $TextBox.Enabled = 1
 $SaveButton.Enabled = 1
 $GoButton.Enabled = 1
 $GoButton.Focus

EndFunction

Function GoButton_Click($sender, $e)

 Dim $Image, $Graphics, $Font, $Brush

 $Image = $BaseImage.Clone(0,0,$BaseImage.Width, $BaseImage.Height)

 $Graphics = $System.Graphics.FromImage($Image)

 $Font = $Form.Font
 $Brush = $System.SolidBrush($System.Color.White)

 $Graphics.DrawString($TextBox.Text, $Font, $Brush, 10, 10)

 $PictureBox.Image = $Image

EndFunction

Function SaveButton_Click($sender, $e)

 $SaveFileDialog.Filename = GetFreeFileName($SaveFileDialog.InitialDirectory, "Untitled", "jpg")

 If $SaveFileDialog.ShowDialog <> $System.DialogResult_Ok
  Return
 Endif

 $Image = $PictureBox.Image

 $Image.Save($SaveFileDialog.Filename)
 
EndFunction

Function ExitMenu_Click($sender, $e)

 Quit

EndFunction

Function GetFreeFilename($Dir, $Name, $Ext)
 Dim $Free
 Dim $Index
 Dim $FileName
 $Index = 1
 Do
  $Free = 0
  $FileName = $Dir + "\" + $Name + $Index + "." + $Ext
  If Not Exist($FileName)
   $Free = 1
  Endif
  $Index = $Index + 1
 Until $Free = 1
 $GetFreeFilename = $FileName
EndFunction




NTDOCAdministrator
(KiX Master)
2008-03-12 07:50 AM
Re: Easy123 Business Card Maker

Thanks a lot for creating and sharing that Shawn. Looks sweet.

Mart
(KiX Supporter)
2008-03-12 02:02 PM
Re: Easy123 Business Card Maker

Cool.

One question. The template card is done in Windows CardSpace right?


ShawnAdministrator
(KiX Supporter)
2008-03-12 02:12 PM
Re: Easy123 Business Card Maker

I don't know what Windows Cardspace is. I just googled for some business cards and renamed the .JPG to .CRD ... to keep them separate.

Mart
(KiX Supporter)
2008-03-12 02:19 PM
Re: Easy123 Business Card Maker

LOL
CardSpace is part of .net 3.0. It sits in the control panel. If installed all .crd files are linked to CardSpace. Been playing around with CardSpace and wondered how you exported one card. Guess you didn't.


Mart
(KiX Supporter)
2008-03-12 05:22 PM
Re: Easy123 Business Card Maker

Shawn (or anybody else with am idea),

Been playing around with it a bit and found a weird issue.
When I use the image included in the download as a template I get nice small data on the card but when I use a image I made myself (same dimensions as the included image) I get huge letters on the card. Is there a way to control the font size and the font itself that it is drawing on the template?


ShawnAdministrator
(KiX Supporter)
2008-03-12 06:08 PM
Re: Easy123 Business Card Maker

Thats weird yeah. Just wonder if there is something else going on here. I used the default font of the "the form" for the drawing.

ShawnAdministrator
(KiX Supporter)
2008-03-12 06:36 PM
Re: Easy123 Business Card Maker

Here's a version with a little font button on it ...

 Code:
Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form()
$Form.Text = "Easy123 Business Card Maker"
$Form.ClientWidth = 640
$Form.ClientHeight = 300
$Form.FontSize = 10

$BaseFont = $Form.Font

$PictureBox = $Form.Controls.Add($System.PictureBox())
$PictureBox.BackColor = $System.Color.AppWorkspace
$PictureBox.Dock = $System.DockStyle_Fill
$PictureBox.BorderStyle = $System.BorderStyle_Fixed3D

$Splitter = $Form.Controls.Add($System.Splitter())
$Splitter.Dock = $System.DockStyle_Left

$Panel = $Form.Controls.Add($System.Panel())
$Panel.Dock = $System.DockStyle_Left

$OpenButton = $Panel.Controls.Add($System.Button())
$OpenButton.Left = 10
$OpenButton.Top = 5
$OpenButton.Width = 150
$OpenButton.Text = "1) Open a template..."
$OpenButton.TextAlign = $System.ContentAlignment_MiddleLeft
$OpenButton.Enabled = 1
$OpenButton.Click = "OpenButton_Click($$System.Sender, $$System.EventArgs)"

$GoButton = $Panel.Controls.Add($System.Button())
$GoButton.Left = 10
$GoButton.Top = $OpenButton.Bottom + 5
$GoButton.Width = 150
$GoButton.Text = "2) Make my card --->"
$GoButton.TextAlign = $System.ContentAlignment_MiddleLeft
$GoButton.Enabled = 0
$GoButton.Click = "GoButton_Click($$System.Sender, $$System.EventArgs)"

$TextBox = $Panel.Controls.Add($System.TextBox())
$TextBox.MultiLine = 1
$TextBox.Left = 10
$TextBox.Top = $GoButton.Bottom + 5
$TextBox.Width = $Panel.ClientWidth - $TextBox.Left - 5
$TextBox.Height = 150
$TextBox.Enabled = 0

$SaveButton = $Panel.Controls.Add($System.Button())
$SaveButton.Left = 10
$SaveButton.Top = $TextBox.Bottom + 5
$SaveButton.Width = 150
$SaveButton.Text = "3) Save my card..."
$SaveButton.TextAlign = $System.ContentAlignment_MiddleLeft
$SaveButton.Enabled = 0
$SaveButton.Click = "SaveButton_Click($$System.Sender, $$System.EventArgs)"

$FontButton = $Panel.Controls.Add($System.Button())
$FontButton.Left = 10
$FontButton.Top = $SaveButton.Bottom + 15
$FontButton.Width = 100
$FontButton.Text = "Font..."
;;$FontButton.TextAlign = $System.ContentAlignment_MiddleLeft
$FontButton.Enabled = 0
$FontButton.Click = "FontButton_Click($$System.Sender, $$System.EventArgs)"

$OpenFileDialog = $System.OpenFileDialog()
$OpenFileDialog.InitialDirectory = @SCRIPTDIR
$OpenFileDialog.Filter = "Templates (*.crd)|*.crd|All Files (*.*)|*.*"

$SaveFileDialog = $System.SaveFileDialog()
$SaveFileDialog.Filter = "Images (*.jpg)|*.jpg|All Files (*.*)|*.*"
$SaveFileDialog.InitialDirectory = @CURDIR

$FontDialog = $System.FontDialog()

$Form.Center
$Form.Show

$TextBox.Anchor = 1+4+8

While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function OpenButton_Click($sender, $e)

 If $OpenFileDialog.ShowDialog <> $System.DialogResult_Ok
  Return
 Endif

 $Filename = $OpenFileDialog.FileName

 $BaseImage = $System.Bitmap.FromFile($Filename)

 $PictureBox.Image = $BaseImage

 $TextBox.Text = ""
 $TextBox.Text = $TextBox.Text + "John Doe" + @CRLF
 $TextBox.Text = $TextBox.Text + "Burbank Town Center" + @CRLF
 $TextBox.Text = $TextBox.Text + "201 East Magnolia, Suite 151" + @CRLF
 $TextBox.Text = $TextBox.Text + "Burbank, California  91502" + @CRLF
 $TextBox.Text = $TextBox.Text + "(818) 566-8556" + @CRLF

 $TextBox.Enabled = 1
 $SaveButton.Enabled = 1
 $FontButton.Enabled = 1
 $GoButton.Enabled = 1
 $GoButton.Focus

EndFunction

Function GoButton_Click($sender, $e)

 Dim $Image, $Graphics, $Font, $Brush

 $Image = $BaseImage.Clone(0,0,$BaseImage.Width, $BaseImage.Height)

 $Graphics = $System.Graphics.FromImage($Image)

 $Brush = $System.SolidBrush($System.Color.White)

 $Graphics.DrawString($TextBox.Text, $BaseFont, $Brush, 10, 10)

 $PictureBox.Image = $Image

EndFunction

Function SaveButton_Click($sender, $e)

 $SaveFileDialog.Filename = GetFreeFileName($SaveFileDialog.InitialDirectory, "Untitled", "jpg")

 If $SaveFileDialog.ShowDialog <> $System.DialogResult_Ok
  Return
 Endif

 $Image = $PictureBox.Image

 $Image.Save($SaveFileDialog.Filename)
 
EndFunction

Function FontButton_Click($sender, $e)

 $FontDialog.Font = $BaseFont

 If $FontDialog.ShowDialog <> $System.DialogResult_Ok
  Return
 Endif

 $BaseFont = $FontDialog.Font

EndFunction

Function ExitMenu_Click($sender, $e)

 Quit

EndFunction

Function GetFreeFilename($Dir, $Name, $Ext)
 Dim $Free
 Dim $Index
 Dim $FileName
 $Index = 1
 Do
  $Free = 0
  $FileName = $Dir + "\" + $Name + $Index + "." + $Ext
  If Not Exist($FileName)
   $Free = 1
  Endif
  $Index = $Index + 1
 Until $Free = 1
 $GetFreeFilename = $FileName
EndFunction




ShawnAdministrator
(KiX Supporter)
2008-03-12 06:41 PM
Re: Easy123 Business Card Maker

I didn't even check-out what this "Saroben" thingy is ... hmmmm

ShawnAdministrator
(KiX Supporter)
2008-03-12 06:48 PM
Re: Easy123 Business Card Maker

Here's an idea. Hook this script in Active Directory and run-off a bunch of business card (outlook sig cards whatever) for everyone in your entire company. Then mail them out. Upper management will be so impressed, they will give you a huge bonus and maybe even promote you. Don't forget to share the wealth with your lowly brethren on Korg.

Mart
(KiX Supporter)
2008-03-12 06:54 PM
Re: Easy123 Business Card Maker

Thanks. Works like a charm.

BTW Saroben does website temples, flash templates and other graphic work.
http://www.saroben.com


ShawnAdministrator
(KiX Supporter)
2008-03-12 06:58 PM
Re: Easy123 Business Card Maker

Sweet. If you just want to set it and forget it, use this up around the top there:

$BaseFont = $System.Font("Courier New", 12, $Form.Font.Style)


-Shawn


Mart
(KiX Supporter)
2008-03-12 06:59 PM
Re: Easy123 Business Card Maker

 Originally Posted By: Shawn
Here's an idea. Hook this script in Active Directory and run-off a bunch of business card (outlook sig cards whatever) for everyone in your entire company.
....


That was my idea as well. That’s why I was playing with it. I don’t really feel like creating all cards lets says each day by hand so hooking it to AD and automatic some stuff is where I'm going.

 Originally Posted By: Shawn

....
Upper management will be so impressed, they will give you a huge bonus and maybe even promote you. Don't forget to share the wealth with your lowly brethren on Korg.


The bonus is more then welcome (just got a quote to repair my car \:o \:\( ). I'll send you a six pack or something if they fork out something to me.


ShawnAdministrator
(KiX Supporter)
2008-03-12 07:01 PM
Re: Easy123 Business Card Maker

Yeah, a batch-type kix script hooked into AD could pump-out jpg's in no time.

masken
(MM club member)
2008-03-12 07:10 PM
Re: Easy123 Business Card Maker

Cool, didn't know KiXforms could render text on an image. You da man as usual shawn \:\) Is there any anti-aliasing available?

Distribution isn't an issue. Personally I solve this in the login script. Of course image size is an issue.


ShawnAdministrator
(KiX Supporter)
2008-03-12 07:30 PM
Re: Easy123 Business Card Maker

I thought size didn't matter ? And anti-aliasing - I don't even know what that really is. You talking that fancy-schmancy XP stuff ? ;-)

-Shawn


masken
(MM club member)
2008-03-12 08:17 PM
Re: Easy123 Business Card Maker

I mean de-pixelating the text generated on the image (ie, compare with ClearType). Like if you type stuff in Photoshop and then render it.



btw, I've also found an object - Imagemagick's COM+ object, but it's poorly documented.


NTDOCAdministrator
(KiX Master)
2008-03-12 08:55 PM
Re: Easy123 Business Card Maker

 Originally Posted By: masken
btw, I've also found an object - Imagemagick's COM+ object, but it's poorly documented.


That is the program I was talking about in your other post Masken. But normally used with PHP, but can be used with other tools.


ShawnAdministrator
(KiX Supporter)
2008-03-12 09:24 PM
Re: Easy123 Business Card Maker

Just load that COM object into VB or VBE (office) as a reference and fire-up the object browser on it. WIll at least show you all the methods and properties and maybe even a one-liner help on each.

Mart
(KiX Supporter)
2008-03-12 10:32 PM
Re: Easy123 Business Card Maker

Seems like the issues with the font size I had had something to do with the template I made and resized to an acceptable size.
Running it on the original image all is fine. Nevertheless thanks for the font selection stuff.

I got it all working with hardcoded data and will do the AD stuff at work tomorrow. Anybody interested in the results?


ShawnAdministrator
(KiX Supporter)
2008-03-12 10:55 PM
Re: Easy123 Business Card Maker

So you going to have it like scan an OU, query the users, pull the details, print the details and pump out a bunch of like "username.jpg" files ?

Mart
(KiX Supporter)
2008-03-12 11:13 PM
Re: Easy123 Business Card Maker

If all goes well and my CEO agrees on it then yes.
Have to find out a way to put them in outlook as a default sig but I think that can't be that hard.
I think we are going to reference them from our website and not include it in the mail to keep mail size down and always have the most recent sig, also in old mails send with an earlier sig.


ShawnAdministrator
(KiX Supporter)
2008-03-12 11:25 PM
Re: Easy123 Business Card Maker

While your in AD, why not just grab the user's home drive mapping, and slap it down there, they can pick it up at their convenience. What you can do though, is post one of the sigs you create, for all to see (sanitized of course).


NTDOCAdministrator
(KiX Master)
2008-03-13 02:37 AM
Re: Easy123 Business Card Maker

I am, I am - Just wish work would quit coming up with fire drill projects and things so I could get back to doing some actual KiX coding.

Haven't actually done any NEW coding for a while now.


Mart
(KiX Supporter)
2008-03-13 09:48 AM
Re: Easy123 Business Card Maker

 Originally Posted By: Shawn
While your in AD, why not just grab the user's home drive mapping, and slap it down there, they can pick it up at their convenience.
....


Hmmm... not sure about that. Sigs in e-mail are mandatory for all our employees so putting it on the user's home drive so they can use it when they feel like it is an option but only for other stuff then e-mail. E-mail will get a default sig that is always there.


NTDOCAdministrator
(KiX Master)
2008-03-14 09:41 AM
Re: Easy123 Business Card Maker

Well it works... now just need to work on some more coding for it.



masken
(MM club member)
2008-03-14 04:20 PM
Re: Easy123 Business Card Maker

So.. is there a way to get rid of the jagged text-edges with KiXforms? Would be a preffered solution of course to do this in KiXforms only \:\)

@shawn, how would I load it into the Office VB-thing? Wasn't there a reosurce explorer or something too?


ShawnAdministrator
(KiX Supporter)
2008-03-14 08:26 PM
Re: Easy123 Business Card Maker

Yeah, you can hop into Office VBE and add Kixforms (or any COM object) as "a reference" than view it with Object Viewer.

masken
(MM club member)
2008-03-16 11:24 AM
Re: Easy123 Business Card Maker

ah, finally got it...

Start Word > hit Alt+F11 > Tools > References > [v] KiXforms .NET

Then start a new module. Right-click and choose object viewer. But tere doesn't seem to be a way to only view classes/protperties from a certain library?

btw; was there an anti-aliasing function already in Kixforms?


ShawnAdministrator
(KiX Supporter)
2008-03-16 01:47 PM
Re: Easy123 Business Card Maker

I usually do this ...

In Excel do this ...

Tools->Macro->VBE

In VBE do this ...

Tools->Referenences->Kixforms.Net

View->Object Browser

All Libraries (combobox) -> Kixforms_System

Or any other COM component you see/add.