
;=============================================================================== ; ; Program Name: CoolText Client ; Description:: Uses [url="http://www.cooltext.com"]www.cooltext.com[/url] to generate images ; Requirement(s): AutoIt Beta ; Author(s): RazerM ; ;=============================================================================== ; #include <GUIConstants.au3> #include <IE.au3> #include <GuiCombo.au3> #include <file.au3> #include "table.au3" #include <misc.au3> #include <Color.au3> #include "image.au3" #include "Progress.au3" Opt("ColorMode", 1) Opt("TrayIconDebug", 1) GUICreate("Cool Text Client", 600, 350) $error = ObjEvent("AutoIt.Error","Err") ;style GUICtrlCreateLabel("Style:", 10, 13) $style = GUICtrlCreateCombo("", 60, 10, 130) $styles = "3D Outline Gradient|3D Outline Textured|Alien Glow|Animated Glow|Blended|Bovinated|Burning|Carved|Chalk|Chrome One|Chrome Two|Comic" & _ "|Cool Metal|Crystal|Cutout|Felt|Fire|Glossy|Glowing Hot|Glowing Steel|Gradient Bevel|Neon|Nova|Old Stone|Outline|Simple|Slab|Starburst|Textured" GUICtrlSetData($style, $styles, "3D Outline Gradient") ;text GUICtrlCreateLabel("Text:", 200, 13) $text = GUICtrlCreateInput("", 230, 10, 350) ;text size GUICtrlCreateLabel("Text Size:", 10, 43) $textsize = GUICtrlCreateInput(70, 60, 40, 65) ;File format GUICtrlCreateLabel("File Format:", 170, 43) $format = GUICtrlCreateCombo("", 230, 40, 240) GUICtrlSetData($format, ".GIF|.GIF with Transparency|.GIF with Transparency, No Dither|.JPG|.PNG|.PNG with Transparency (Not supported in IE)", ".PNG");|.PSD (Photoshop with Layers)", ".PNG") ;background colour GUICtrlCreateLabel("Colour:", 10, 73) $color = _GUICtrlCreateTable(50, 73, 3, 2, 60, 20) $combined = _GUICtrlTableSpan($color, 1, 2, 3, 2) GUICtrlSetData($color[1][1], "255") GUICtrlSetData($color[2][1], "255") GUICtrlSetData($color[3][1], "255") GUICtrlSetBkColor($color[3][1],0xff0000) GUICtrlSetBkColor($color[2][1],0x00ff00) GUICtrlSetBkColor($color[1][1],0x0000ff) GUICtrlSetBkColor($combined,0xffffff) $changecol = GUICtrlCreateButton("Change", 240, 73, 80, 25) ;render button $render = GUICtrlCreateButton("Render", 420, 315, 80, 25) $view = GUICtrlCreateButton("View Image", 505, 315, 80, 25) GUICtrlSetState($view, $GUI_DISABLE) GUISetState() $winpos = WinGetPos("Cool Text Client") $a_styles = StringSplit($styles, "|") $prefile = StringLower(StringReplace($a_styles[1], " ", "")) & ".gif" InetGet("[url="http://frazergmclean.googlepages.com/"]http://frazergmclean.googlepages.com/[/url]" & $prefile, @TempDir & "\image.gif") $prefilesaved = @TempDir & "\image.gif" Dim $size = _ImageGetSize($prefilesaved) SplashImageOn("Font Preview", $prefilesaved, $size[0], $size[1], -1, $winpos[1] - $size[1] - 5, 17) $splash = 1 Dim $lastcolor = 0xFFFFFF, $ie, $lastfile = "", $oldpos = WinGetPos("Cool Text Client"), $old_string = "" While 1 If Not WinActive("Cool Text Client") Then SplashOff() $splash = 0 EndIf If $splash <> WinActive("Cool Text Client") Then Splash() $newpos = WinGetPos("Cool Text Client") If $newpos[0]+$newpos[1] <> $oldpos[0]+$oldpos[1] Then Splash() $oldpos = WinGetPos("Cool Text Client") _GUICtrlComboAutoComplete ($style, $old_string) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $render If (_GUICtrlComboGetCurSel($style)+1 = 4) Or (_GUICtrlComboGetCurSel($style)+1 = 7) Then GUICtrlSetData($format, ".GIF") GUICtrlSetState($format, $GUI_DISABLE) $i_skip = 1 Else $i_skip = 0 GUICtrlSetState($format, $GUI_ENABLE) EndIf $lastfile = _Render(GUICtrlRead($style), GUICtrlRead($text), GUICtrlRead($textsize), _GUICtrlComboGetCurSel($format)+1, $lastcolor, $i_skip) ;+1 corrects from 0 based index Case $changecol $colorpick = _ChooseColor(1, $lastcolor, 1) If Not @error Then $lastcolor = $colorpick GUICtrlSetBkColor($combined, $colorpick) $blue = _ColorGetRed($colorpick) GUICtrlSetData($color[3][1], $blue) $green = _ColorGetGreen($colorpick) GUICtrlSetData($color[2][1], $green) $red = _ColorGetBlue($colorpick) GUICtrlSetData($color[1][1], $red) EndIf Case $style Splash() Case $view If $lastfile <> "" Then RunWait(@ComSpec & ' /c rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen ' & FileGetShortName($lastfile), '', @SW_HIDE) EndSwitch WEnd Func _Render($style, $s_text, $i_size, $i_file, $i_bkcolor, $i_skip) SplashOff() Dim $progress, $main, $sub $progress = _ProgressOn($progress, $main, $sub, "Connecting", "Creating IE Object", 170, 150) ; open IE and navigate to cooltext _ProgressSet($progress, 4, "Navigating to [url="http://cooltext.com"]http://cooltext.com[/url]") $ie = _IECreate("[url="http://cooltext.com"]http://cooltext.com[/url]", 0, 0) If @error Then Err() ;two if statements to fix style bug If $style = "Textured" Then _IEImgClick($ie, $style, "alt", 1, 1) If @error Then Err() If $style <> "Textured" Then _IEImgClick($ie, $style, "alt", 0, 1) If @error Then Err() ;retrieve form _ProgressSet($progress, 8, "Loading Form", "Setting Values") _IELoadWait($ie) $form = _IEFormGetCollection($ie, 0) If @error Then Err() ;retrieve text field _ProgressSet($progress, 12, "Loading Text Field") $text = _IEFormElementGetObjByName($form, "Text") If @error Then Err() ;set value _ProgressSet($progress, 16, "Setting Text Field") Sleep(500) _IEFormElementSetValue($text, $s_text) If @error Then Err() Sleep(1000) ;retrieve fontsize field _ProgressSet($progress, 20, "Loading Fontsize Field") $size = _IEFormElementGetObjByName($form, "FontSize") If @error Then Err() ;setvalue _ProgressSet($progress, 24, "Setting Fontsize Field") _IEFormElementSetValue($size, $i_size) If @error Then Err() If $i_skip = 0 Then ;retrieve file format field _ProgressSet($progress, 28, "Loading FileFormat Field") $fileformat = _IEFormElementGetObjByName($form, "FileFormat") If @error Then Err() ;set value _ProgressSet($progress, 32, "Setting FileFormat Field") _IEFormElementSetValue($fileformat, $i_file) If @error Then Err() EndIf ;retrieve background colour fields _ProgressSet($progress, 36, "Loading Background Colour Fields") $red = _IEFormElementGetObjByName($form, "BackgroundColor_red") If @error Then Err() $green = _IEFormElementGetObjByName($form, "BackgroundColor_green") If @error Then Err() $blue = _IEFormElementGetObjByName($form, "BackgroundColor_blue") If @error Then Err() ;set background colour _ProgressSet($progress, 40, "Setting Background Colour Fields") _IEFormElementSetValue($red, _ColorGetBlue($i_bkcolor)) If @error Then Err() _IEFormElementSetValue($green, _ColorGetGreen($i_bkcolor)) If @error Then Err() _IEFormElementSetValue($blue, _ColorGetRed($i_bkcolor)) If @error Then Err() ;click render button using loop (i had trouble using other ways) _ProgressSet($progress, 44, "Loading All Form Submit Button's", "Submitting Data") $Inputs = _IETagNameGetCollection($form.document, "input") If @error Then Err() For $Input in $Inputs If String($Input.value) = "Render Logo Design" Then _ProgressSet($progress, 48, "Clicking appropriate button") $Input.click ExitLoop EndIf Next ;wait for render _ProgressSet($progress, 52, "Sleeping until Cool Text has generated image") Do Sleep(100) If StringIsDigit(StringLeft(StringRight(_IEGetProperty($ie, "locationname"), 16), 1)) Then _ProgressSet($progress, 56, "Sleeping until Cool Text has generated image", StringRight(_IEGetProperty($ie, "locationname"), 16)) Else _ProgressSet($progress, 56, "Sleeping until Cool Text has generated image", "0 Rendering Jobs") EndIf If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit Until _IEGetProperty($ie, "locationname") = "Cool Text: Generated Image" ;split url to find image code _ProgressSet($progress, 60, "Splitting URL", "Retrieving Image") $url = _IEGetProperty($ie, "locationurl") If @error Then Err() _ProgressSet($progress, 65, "Finding Unique Code") $code = StringRight($url, 8) ;extension _ProgressSet($progress, 70, "Assigning extension to variable") $ext = StringLeft(GUICtrlRead($format), 4) ;download image _ProgressSet($progress, 75, "Retrieving all image tags") $imgs = _IETagNameGetCollection($ie.document, "img") If @error Then Err() _ProgressSet($progress, 80, "Please save the file...") $save = FileSaveDialog("Save Image", @DesktopCommonDir, "Image Files (*" & $ext & ")", 16) _CheckExt($save, $ext) If FileExists($save) Then FileDelete($save) _ProgressSet($progress, 85, "Splitting Save Path") Local $szDrive, $szDir, $szFName, $szExt $a_SplitFile = _PathSplit($save, $szDrive, $szDir, $szFName, $szExt);0 based array If @error Then Err() _ProgressSet($progress, 90, "Finding and saving image") For $img In $imgs $url = $img.src $imgfile = $img.nameProp If StringInStr($url, $code) And StringInStr($imgfile, "cooltext") Then INetGet($url, $a_SplitFile[1] & $a_SplitFile[2] & $imgfile, 1, 0) ;only if the image has the code in it's name ExitLoop EndIf Next _ProgressSet($progress, 94, "Renaming to desired filename") If _FileRename($a_SplitFile[1] & $a_SplitFile[2] & $imgfile, $a_SplitFile[3]) = 0 Then Err() _ProgressSet($progress, 100) _ProgressOff($progress) _IEQuit($ie) GUICtrlSetState($view, $GUI_ENABLE) Splash() Return $a_SplitFile[1] & $a_SplitFile[2] & $a_SplitFile[3] & $ext EndFunc ;these are made by me Func Splash() SplashOff() $winpos = WinGetPos("Cool Text Client") If (_GUICtrlComboGetCurSel($style)+1 <> 4) And (_GUICtrlComboGetCurSel($style)+1 <> 7) Then $prefile = StringLower(StringReplace($a_styles[_GUICtrlComboGetCurSel($style)+1], " ", "")) & ".gif" InetGet("[url="http://frazergmclean.googlepages.com/"]http://frazergmclean.googlepages.com/[/url]" & $prefile, @TempDir & "\image.gif") $prefilesaved = @TempDir & "\image.gif" Dim $size = _ImageGetSize($prefilesaved) SplashImageOn("Font Preview", $prefilesaved, $size[0], $size[1], ($winpos[0]+300)-($size[0]/2), $winpos[1] - $size[1] - 5, 17) $splash = 1 EndIf EndFunc Func _CheckExt(ByRef $s_file, $s_ext) If StringRight($s_file, StringLen($s_ext)) <> $s_ext Then $s_file = $s_file & $s_ext EndFunc Func _FileRename($s_file, $s_name) If Not FileExists($s_file) Then Return 0 Local $szDrive, $szDir, $szFName, $szExt $a_SplitFile = _PathSplit($s_file, $szDrive, $szDir, $szFName, $szExt) $s_renamed = $a_SplitFile[1] & $a_SplitFile[2] & $s_name & $a_SplitFile[4] If Not FileMove($a_SplitFile[0], $s_renamed) Then Return 0 If Not FileExists($s_renamed) Then Return 0 If FileExists($s_file) Then FileDelete($s_file) Return 1 EndFunc Func Err() MsgBox(48, "Error", "An error occurred" & @LF & "Please try again") _IEQuit($ie) ProgressOff() Exit EndFunc
You need these UDF's:
image.au3 5.88K
852 downloads
table.au3 4.24K
749 downloads
Edited by RazerM, 25 May 2006 - 09:57 PM.

















