Page 1 of 2 12>
Topic Options
#186149 - 2008-03-12 04:29 AM Easy123 Business Card Maker
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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



Top
#186153 - 2008-03-12 07:50 AM Re: Easy123 Business Card Maker [Re: Shawn]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Thanks a lot for creating and sharing that Shawn. Looks sweet.
Top
#186160 - 2008-03-12 02:02 PM Re: Easy123 Business Card Maker [Re: Shawn]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Cool.

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

- Chuck Norris once sold ebay to ebay on ebay.

Top
#186161 - 2008-03-12 02:12 PM Re: Easy123 Business Card Maker [Re: Mart]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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.
Top
#186162 - 2008-03-12 02:19 PM Re: Easy123 Business Card Maker [Re: Shawn]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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.


Edited by Mart (2008-03-12 04:24 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#186166 - 2008-03-12 05:22 PM Re: Easy123 Business Card Maker [Re: Shawn]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#186168 - 2008-03-12 06:08 PM Re: Easy123 Business Card Maker [Re: Mart]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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.
Top
#186170 - 2008-03-12 06:36 PM Re: Easy123 Business Card Maker [Re: Shawn]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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



Top
#186171 - 2008-03-12 06:41 PM Re: Easy123 Business Card Maker [Re: Shawn]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I didn't even check-out what this "Saroben" thingy is ... hmmmm
Top
#186172 - 2008-03-12 06:48 PM Re: Easy123 Business Card Maker [Re: Shawn]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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.
Top
#186173 - 2008-03-12 06:54 PM Re: Easy123 Business Card Maker [Re: Shawn]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Thanks. Works like a charm.

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

- Chuck Norris once sold ebay to ebay on ebay.

Top
#186174 - 2008-03-12 06:58 PM Re: Easy123 Business Card Maker [Re: Mart]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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

Top
#186175 - 2008-03-12 06:59 PM Re: Easy123 Business Card Maker [Re: Shawn]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 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.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#186176 - 2008-03-12 07:01 PM Re: Easy123 Business Card Maker [Re: Mart]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Yeah, a batch-type kix script hooked into AD could pump-out jpg's in no time.
Top
#186179 - 2008-03-12 07:10 PM Re: Easy123 Business Card Maker [Re: NTDOC]
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
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.


Edited by masken (2008-03-12 07:16 PM)
_________________________
The tart is out there

Top
#186181 - 2008-03-12 07:30 PM Re: Easy123 Business Card Maker [Re: masken]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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

Top
#186186 - 2008-03-12 08:17 PM Re: Easy123 Business Card Maker [Re: Shawn]
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
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.


Edited by masken (2008-03-12 08:49 PM)
_________________________
The tart is out there

Top
#186190 - 2008-03-12 08:55 PM Re: Easy123 Business Card Maker [Re: masken]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
 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.

Top
#186193 - 2008-03-12 09:24 PM Re: Easy123 Business Card Maker [Re: NTDOC]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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.
Top
#186199 - 2008-03-12 10:32 PM Re: Easy123 Business Card Maker [Re: Shawn]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.085 seconds in which 0.026 seconds were spent on a total of 15 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org