|
|
|||||||
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 |
||||||||
|
|
|||||||
Thanks a lot for creating and sharing that Shawn. Looks sweet. |
||||||||
|
|
|||||||
Cool. One question. The template card is done in Windows CardSpace right? |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
I didn't even check-out what this "Saroben" thingy is ... hmmmm |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Thanks. Works like a charm. BTW Saroben does website temples, flash templates and other graphic work. http://www.saroben.com |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 ). I'll send you a six pack or something if they fork out something to me. |
||||||||
|
|
|||||||
Yeah, a batch-type kix script hooked into AD could pump-out jpg's in no time. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
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 ? |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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). |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Well it works... now just need to work on some more coding for it. |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
Yeah, you can hop into Office VBE and add Kixforms (or any COM object) as "a reference" than view it with Object Viewer. |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
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. |