관리 메뉴

ㄴrㅎnㅂrㄹrㄱi

글자를 포함한 스크린 샷을 찍습니다. 본문

AUTOHOTKEY/스크립트

글자를 포함한 스크린 샷을 찍습니다.

님투 2007. 12. 22. 15:14
반응형

TextToImage 1.07 - Write text onto an image or screenshot

  1. SetWorkingDir %A_ScriptDir%
  2. #Include, TextToImage-1.07.ahk
  3.  
  4. Gui, 1: Add, Text, x10 y10 w300 r1 - Multi - Wrap, In parameter ( Screen, Window or image location):
  5. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vIn, Screen
  6. Gui, 1: Add, Text, x10 y+10 w300 r1 - Multi - Wrap, Text to write:
  7. Gui, 1: Add, Edit, x10 y+10 w300 r3 vText, %A_DDDD%`, %A_DD%/%A_MM%/%A_YYYY% - %A_Hour%:%A_Min%:%A_Sec%`nTextToImage by tic
  8. Gui, 1: Add, Text, x10 y+10 w300 r2, Output filename and location`n(can have extension bmp,jpg,png,tif,gif):
  9. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vOutput, Screenshot.png
  10. Gui, 1: Add, Text, x10 y+10 w300 r1 - Multi - Wrap, X-Position (Can be a ratio of width eg. 1:2)
  11. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vXPos, 1:2
  12. Gui, 1: Add, Text, x10 y+10 w300 r1 - Multi - Wrap, Y-Position (Can be a ratio of height eg. 9:10)
  13. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vYPos, 9:10
  14. Gui, 1: Add, Text, x10 y+10 w300 r1 - Multi - Wrap, Text size:
  15. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vSize, 30
  16. Gui, 1: Add, Text, x10 y+10 w300 r1 - Multi - Wrap, Text alignment ( Top, Bottom,Centre, Left, Right):
  17. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vAlign, Bottom|Centre
  18. Gui, 1: Add, Text, x10 y+10 w300 r1 - Multi - Wrap, Text weight:
  19. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vWeight, 1000
  20. Gui, 1: Add, Text, x10 y+10 w300 r1 - Multi - Wrap, Text font:
  21. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vFont, Arial
  22. Gui, 1: Add, Text, x10 y+10 w300 r1 - Multi - Wrap, Text colour ( RGB):
  23. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vTColour, 401270
  24. Gui, 1: Add, Text, x10 y+10 w300 r1 - Multi - Wrap, Text style ( Underline, Italic,Strikeout or none):
  25. Gui, 1: Add, Edit, x10 y+10 w300 r1 - Multi - Wrap vStyle, Italic
  26. Gui, 1: Add, Button, x120 y+20 w75 r1 - Multi - Wrap gCreate Default, Create
  27. Gui, 1: Show, AutoSize, TextToImage Example1
  28.  
  29. Create:
  30. E := TextToImage( In, Text, Output, XPos, YPos, Size, Align, Weight, Font, TColour, Style)
  31. ;MsgBox, %E%
  32.  



 

  1. ; TextToImage v1.07 by tic
  2. ;
  3. ; TextToImage can overlay writing to a screenshot of the entire screen or active window, or from an existing image and write to file
  4. ; TextToImage(In, Text, Output, x, y, Font, TColour, Size, Weight)
  5. ;
  6. ; In: Can either be the "Screen" or "Window" and will take a screenshot of the respective choice, or the location of an exisitng image
  7. ;
  8. ; Text: This is the text to overlay onto the screenshot
  9. ;
  10. ; Output: This is the path and filename that the image will be written to.
  11. ; The extension can be .bmp,.jpg,.png,.tif,.gif and will be written as that type accordingly
  12. ;
  13. ; x: This is the x-coordinate to place the text. This coordinate will be the distance from the left the text will be placed.
  14. ; This value may be a ratio. For instance 4:5 would place the text at the position 4/5ths of the width of the image
  15. ; You must also consult which mode align is in
  16. ;
  17. ; y: This is the y-coordinate to place the text. This coordinate will be the distance from the top the text will be placed.
  18. ; This value may be a ratio. For instance 1:3 would place the text at the position 1/3ths of the height of the image
  19. ; You must also consult which mode align is in
  20. ;
  21. ; Size: This is the height of the text in pixels
  22. ;
  23. ; Align: This must have 2 styles set, The text's x placement (Left,Centre,Right) and the text's y placement (Top,Bottom)
  24. ; It must be used for example as Left|Bottom - This would place the text at the bottom of it's bounding area and aligned left
  25. ;
  26. ; Weight: This is the boldness of the text. Make the value greater to make it more bold
  27. ;
  28. ; Font: This is the font to set the text to be
  29. ; Examples are: Arial, Bookman Old Style, Times New Roman
  30. ;
  31. ; TColour: This is the colour to set the text in RGB format.
  32. ; So FF0000 is red
  33. ;
  34. ; Style: Can contain the words Underline,Italic,Strikeout and will set the text in the appropriate styles
  35.  
  36. TextToImage( In="Screen", Text="TextToImage", Output="TextToImage.bmp", x="1:2", y="1:2", Size="20", Align="Bottom|Centre", Weight="400", Font="Arial", TColour="000000", Style="")
  37. {
  38.     hGdiPlus := DllCall("LoadLibrary", "Str", "gdiplus.dll")
  39.     VarSetCapacity(si, 16, 0), si := Chr(1)
  40.     DllCall("gdiplusGdiplusStartup", "UIntP", pToken, "UInt", &si, "UInt", 0)
  41.  
  42.     If In in Screen,Window
  43.     {
  44.         If ( In = "Screen")
  45.         nL := nT := 0, nW := A_ScreenWidth, nH := A_ScreenHeight                        ; Get coordinates for full screen
  46.         Else If ( In = "Window")
  47.         {
  48.             WinGetPos, nL, nT, nW, nH, A                                                ; Get coordinates for active window
  49.             WinGet, ID, ID, A
  50.             WinGetTitle, Title, A
  51.             Winget, MinMax, MinMax, A
  52.             If !( DllCall("IsWindowVisible", UInt, ID) && (Title) && ( MinMax != -1))     ; Check active window is visible
  53.             {
  54.                 GoSub, TTS_GdiplusShutdown
  55.                 Return, "Window is not visible"
  56.             }
  57.         }      
  58.         mDC := DllCall("CreateCompatibleDC", "UInt", 0)
  59.         NumPut( VarSetCapacity(bi, 40, 0), bi)
  60.         NumPut(nW, bi, 4)
  61.         NumPut(nH, bi, 8)
  62.         NumPut(32, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
  63.         hBM := DllCall("gdi32CreateDIBSection", "UInt", mDC, "UInt", &bi, "UInt", 0, "UIntP", "", "UInt", 0, "UInt", 0)
  64.         oBM := DllCall("SelectObject", "UInt", mDC, "UInt", hBM)                        ; Place bitmap object Into compatible DC
  65.         hDC := DllCall("GetDC", "UInt", 0)                                            ; Get DC of screen and bitblt either whole screen or active window
  66.         DllCall("BitBlt", "UInt", mDC, "Int", 0, "Int", 0, "Int", nW, "Int", nH, "UInt", hDC, "Int", nL, "Int", nT, "UInt", 0x40000000|0x00CC0020)
  67.     }
  68.     Else
  69.     {
  70.         VarSetCapacity(wFile, StrLen( In)*2+2)
  71.         DllCall("kernel32MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &In, "Int", -1, "UInt", &wFile, "Int", VarSetCapacity(wFile)//2)
  72.         DllCall("gdiplusGdipCreateBitmapFromFile", "UInt", &wFile, "UIntP", pBitmap)
  73.  
  74.         If !pBitmap
  75.         {
  76.             Gosub, TTS_GdiplusShutdown
  77.             Return, "Failed to load image"
  78.         }
  79.       
  80.         DllCall("gdiplusGdipCreateHBITMAPFromBitmap", "UInt", pBitmap, "UIntP", hBM, "UInt", 0)
  81.     DllCall("gdiplusGdipDisposeImage", "Uint", pBitmap)
  82.         mDC := DllCall("CreateCompatibleDC", "UInt", 0)
  83.         oBM := DllCall("SelectObject", "UInt", mDC, "UInt", hBM)
  84.     hDC := DllCall("GetDC", "UInt", 0)
  85.     }
  86.  
  87.     StringSplit, OutputArray, Output, .
  88.     Extension := "." . OutputArray%OutputArray0%
  89.     If Extension not in .bmp,.jpg,.png,.tif,.gif                                    ; Check file extension is correct
  90.     {
  91.         GoSub, TTS_GdiplusShutdown
  92.         Return, "Invalid file extension. Only bmp,jpg,png,tif,gif are available"
  93.     }
  94.  
  95.     VarSetCapacity(bm, 24, 0)
  96.     If ! DllCall("GetObject", "UInt", hBM, "Int", 24, "UInt", &bm)
  97.     {
  98.         GoSub, TTS_GdiplusShutdown
  99.         Return, "GetObject failed on bitmap {" hBM "}"
  100.     }
  101.     Width := NumGet(bm, 4, "Int")                                                ; Get properties of bitmap
  102.     Height := NumGet(bm, 8, "Int")
  103.     bpp := NumGet(bm, 18, "Ushort")
  104.   
  105.     DllCall("SetBkMode", "UInt", mDC, "UInt", 1)                                  ; Leave background untouched for background mix mode
  106.     DllCall("SetGraphicsMode", "UInt", mDC, "UInt", 2)                          ; Set graphics mode for DC to allow world transformations                          
  107.  
  108.     VarSetCapacity(logfont, 60, 0)
  109.   
  110.     LogPixelsSY := DllCall("GetDeviceCaps", "UInt", hDC, "Int", 90)                ; Number of pixels per logical inch along the screen height
  111.     DllCall("ReleaseDC", "UInt", 0, "UInt", hDC)
  112.     TextHeight := -(Size*logPixelsSY)/72
  113.  
  114.   NumPut(TextHeight, logfont, 0)                          ; Set text height
  115.   ;NumPut(TextWidth, logfont, 4) ; Change text width
  116.  
  117.     NumPut(Weight, logfont, 16)                            ; Set text weight
  118.   If InStr( Style, "Underline")                          ; Set style to be either underline,italic,Strikeout
  119.   NumPut(1, logfont, 21)
  120.   If InStr( Style, "Italic")
  121.   NumPut(1, logfont, 20)
  122.   If InStr( Style, "Strikeout")
  123.   NumPut(1, logfont, 22)
  124.  
  125.   NumPut(5, logfont, 26)                              ; ClearType antialiasing XP and above only
  126.   
  127.     AlignWord := "Right,Top,Bottom,Centre,Left"
  128.     AlignNum := "2,0,8,6,0"
  129.   
  130.     StringSplit, AlignWords, AlignWord, `,
  131.     StringSplit, AlignNums, AlignNum, `,
  132.   
  133.     Loop, %AlignWords0%
  134.     StringReplace, Align, Align, % AlignWords%A_Index%, % AlignNums%A_Index%, All
  135.     StringSplit, Pos, Align, |
  136.     Align := Pos1 | Pos2
  137.  
  138.     StringLeft, FaceName, Font, 32
  139.     DllCall("lStrcpy", "UInt", &logfont + 28, "Str", FaceName)                      ; Set font
  140.     DllCall("SetTextAlign", "UInt", mDC, "UInt", Align)                           ; Align text
  141.     #hFont := DllCall("CreateFontIndirect", "UInt", &logfont)
  142.     #hOldFont := DllCall("SelectObject", "UInt", mDC, "UInt", #hFont)              ; Change DC Font
  143.     TColour := "0x" . TColour
  144.     prevColor := DllCall("SetTextColor", "UInt", mDC, "UInt", ((TColour & 0xFF) << 16) + (TColour & 0xFF00) + ((TColour >> 16) & 0xFF), "UInt")
  145.   
  146.     If InStr(x, ":")
  147.     {
  148.         StringSplit, XRatio, x, :
  149.         XPos := XRatio1*(Width//XRatio2)
  150.     }
  151.   Else
  152.   XPos := x
  153.  
  154.     If InStr(y, ":")                                                                ; Get ratios of x and y position
  155.     {
  156.         StringSplit, YRatio, y, :
  157.         YPos := YRatio1*(Height//YRatio2)
  158.     }
  159.   Else
  160.   YPos := y
  161.   
  162.     StringSplit, Text, Text, `n
  163.       
  164.     Loop, %Text0%
  165.     {  
  166.         DllCall("TextOut", "UInt", mDC, "Int", XPos, "Int", YPos, "Str", Text%A_Index%, "UInt", StrLen(Text%A_Index%))
  167.         YPos += 1.5*Size                                                            ; Draw text Into device
  168.     }  
  169.                                                                                   
  170.     DllCall("SelectObject", "UInt", mDC, "UInt", #hOldFont)
  171.     DllCall("DeleteObject", "UInt", #hFont)                                       ; Restore DC Font
  172.       
  173.     DllCall("gdiplusGdipCreateBitmapFromHBITMAP", "UInt", hBM, "UInt", 0, "UIntP", pImage)
  174.   DllCall("SelectObject", "Uint", mDC, "Uint", oBM)
  175.   DllCall("DeleteObject", "Uint", hBM)
  176.   DllCall("DeleteDC", "Uint", mDC)
  177.     DllCall("gdiplusGdipGetImageEncodersSize", "UIntP", nCount, "UIntP", nSize)    ; Get encoder
  178.     VarSetCapacity(ci, nSize)
  179.     DllCall("gdiplusGdipGetImageEncoders", "UInt", nCount, "UInt", nSize, "UInt", &ci)
  180.       
  181.     Loop, %nCount%
  182.     {
  183.         nSize := DllCall("WideCharToMultiByte", "UInt", 0, "UInt", 0, "UInt", NumGet(ci, 76 * ( A_Index - 1) + 44), "Int", -1, "UInt", 0, "Int",  0, "UInt", 0, "UInt", 0)
  184.         VarSetCapacity(sString, nSize)
  185.         DllCall("WideCharToMultiByte", "UInt", 0, "UInt", 0, "UInt", NumGet(ci, 76 * ( A_Index - 1) + 44), "Int", -1, "Str", sString, "Int", nSize, "UInt", 0, "UInt", 0)
  186.   
  187.         If ! InStr(sString, Extension)                                             ; Find encoder matching extension
  188.         Continue
  189.         pCodec := &ci + 76 * ( A_Index - 1)
  190.         Break
  191.     }
  192.     If pImage                                                                  ; Save image to file
  193.     {
  194.         sString := Output
  195.         nSize := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", 0, "Int", 0)
  196.         VarSetCapacity(wString, nSize * 2)
  197.         DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", &wString, "Int", nSize)
  198.   
  199.         DllCall("gdiplusGdipSaveImageToFile", "UInt", pImage, "UInt", &wString, "UInt", pCodec, "UInt", 0)
  200.     DllCall("gdiplusGdipDisposeImage", "Uint", pImage)
  201.     }
  202.     GoSub, TTS_GdiplusShutdown
  203.     Return, XPos . "|" . YPos
  204.  
  205.   TTS_GdiplusShutdown:
  206.     DllCall("gdiplusGdiplusShutdown" , "UInt", pToken)                           ; Shutdown and free library
  207.     DllCall("FreeLibrary", "UInt", hGdiPlus)
  208. }







 

반응형

'AUTOHOTKEY > 스크립트' 카테고리의 다른 글

Captcha (GUI) - 입력코드 확인  (0) 2007.12.22
HTML 태그 적용 시키기.  (0) 2007.12.22
AHK Chat (Another Method)  (0) 2007.11.25
XML 관련 함수  (0) 2007.11.13
ado com  (0) 2007.11.10
Comments