Last active
June 8, 2021 16:46
-
-
Save zozovo/fb602c740a6149688f041eb5bf02c3e4 to your computer and use it in GitHub Desktop.
An AHK script with GUI for landian editors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. | |
; #Warn ; Enable warnings to assist with detecting common errors. | |
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
#Include Gdip_All.ahk | |
; Start gdi+ | |
If !pToken := Gdip_Startup() | |
{ | |
MsgBox, 48, Gdip error!, Gdip failed to start. | |
ExitApp | |
} | |
; Lantools v3.0 | |
Gui, 1:New, , Lantools | |
Gui, Font, , Tahoma | |
Gui, Margin, 10, 20 | |
; imgs part | |
Gui, Add, Text, Section xm ym w80 +Center , Article ID | |
Gui, Add, Edit, ys wp vArticleID, | |
Gui, Add, Text, ys +Center, Qty | |
Gui, Add, Slider, ys w140 Range1-5 +Tooltip vQty, 1 | |
Gui, Add, Button, Default ys w80 r1 vImageGen, GO | |
Gui, Add, Text, Section xs w80 r6 +Center, Main.png`n751px*$px | |
Gui, Add, Edit, ys w350 r6 -Wrap vLandianImage, | |
Gui, Add, Text, Section xs w80 r2 +Center, Thumbnail`n290*177px | |
Gui, Add, Edit, ys w350 r1 vLandianThumbImage, | |
Gui, Add, Text, Section xs w80 r2 +Center, Slide`n600*364px | |
Gui, Add, Edit, ys w350 r1 vLandianSliderImage, | |
; toolbox part | |
Gui, Add, GroupBox, Section xs w450 r5 +Center, ToolBox | |
Gui, Add, Edit, xp+10 yp+30 w340 r10 vLandianToolBox, | |
Gui, Add, Button, xp+350 yp w80 r1, <a> | |
Gui, Add, Button, yp+30 wp r1, <pre> | |
Gui, Add, Button, yp+30 wp r1, <strong> | |
Gui, Add, DropDownList, yp+30 wp gLandianTitleAndList vLandianTitleAndList, Red Title|Green Title|Blue Title|Yellow Title|Red List|Green List|Blue List|Yellow List | |
Gui, Add, Button, yp+30 wp r1, Clear | |
; hotstring part | |
Gui, Add, Text, Section xs r1, Hotstrings: | |
Gui, Add, Text, ys r1, `;edt [正在编辑] | |
Gui, Add, Text, ys r1, `;adt [待审] | |
Gui, Add, Text, ys r1, `;cb 「」 | |
Gui, Add, Text, ys r1, F9 Thumbnail | |
Gui, Add, Text, ys r1, F10 MainImage | |
; bottom part | |
Gui, Add, Text, xs r1 cGreen, zozovo ❤ MIT License | |
Gui, Show | |
Return | |
; Generate Images tags and links | |
ButtonGO: | |
GuiControlGet, ArticleID | |
GuiControlGet, Qty | |
ArticleID := Trim(ArticleID) | |
LandianImage := "" | |
If (ArticleID != "") { | |
If (Qty = 1) { | |
src := "https://img.lancdn.com/landian/" . A_YYYY . "/" . A_MM . "/" . ArticleID . ".png" | |
LandianImage := "<a href=""" . src . """><img src=""" . src . """ alt=""article title"" class=""alignnone size-full"" /></a>" | |
} else { | |
Loop, %Qty% { | |
src := "https://img.lancdn.com/landian/" . A_YYYY . "/" . A_MM . "/" . ArticleID . "-" . A_Index . ".png" | |
LandianImage .= "<a href=""" . src . """><img src=""" . src . """ alt=""article title"" class=""alignnone size-full"" /></a>`n" | |
} | |
} | |
LandianThumbImage := "https://img.lancdn.com/landian/" . A_YYYY . "/" . A_MM . "/" . ArticleID . "T.png" | |
LandianSliderImage := "https://img.lancdn.com/landian/" . A_YYYY . "/" . A_MM . "/" . ArticleID . "H.png" | |
} | |
GuiControl,, LandianImage, %LandianImage% | |
GuiControl,, LandianThumbImage, %LandianThumbImage% | |
GuiControl,, LandianSliderImage, %LandianSliderImage% | |
Return | |
; warp with <a>, open in new tab | |
Button<a>: | |
GuiControlGet, LandianToolBox | |
Clipboard := LandianToolBox := "<a href=""" . Clipboard . """ target=""_blank"" rel=""noopener"">" . Clipboard . "</a>" | |
GuiControl,, LandianToolBox, %LandianToolBox% | |
Return | |
; warp with <pre> | |
Button<pre>: | |
GuiControlGet, LandianToolBox | |
Clipboard := LandianToolBox := "<pre>`n" . Clipboard . "`n</pre>" | |
GuiControl,, LandianToolBox, %LandianToolBox% | |
Return | |
; warp with red color and <b> | |
Button<strong>: | |
GuiControlGet, LandianToolBox | |
Clipboard := LandianToolBox := "<strong><span style=""color: #019eff;"">" . Clipboard . "</span></strong>" | |
GuiControl,, LandianToolBox, %LandianToolBox% | |
Return | |
; warp with custom code as titles or lists | |
LandianTitleAndList: | |
GuiControlGet, LandianToolBox | |
GuiControlGet, LandianTitleAndList | |
LandianList := "" | |
LandianListArray := StrSplit(Clipboard, "`r`n", " `t`r`n", -1) | |
For k, v in LandianListArray | |
If (v != "") { | |
LandianList .= "<li>" . v . "</li>`n" | |
} | |
LandianList := "<ul>`n" . LandianList . "</ul>" | |
If (LandianTitleAndList = "Blue Title") { | |
LandianToolBox := "[infobox]<strong>" . Clipboard . "</strong>[/infobox]" | |
} Else If (LandianTitleAndList = "Green Title") { | |
LandianToolBox := "[successbox]<strong>" . Clipboard . "</strong>[/successbox]" | |
} Else If (LandianTitleAndList = "Yellow Title") { | |
LandianToolBox := "[warningbox]<strong>" . Clipboard . "</strong>[/warningbox]" | |
} Else If (LandianTitleAndList = "Red Title") { | |
LandianToolBox := "[errorbox]<strong>" . Clipboard . "</strong>[/errorbox]" | |
} Else If (LandianTitleAndList = "Blue List") { | |
LandianToolBox := "[ssbluelist]" . LandianList . "[/ssbluelist]" | |
} Else If (LandianTitleAndList = "Green List") { | |
LandianToolBox := "[ssgreenlist]" . LandianList . "[/ssgreenlist]" | |
} Else If (LandianTitleAndList = "Yellow List") { | |
LandianToolBox := "[ssyellowlist]" . LandianList . "[/ssyellowlist]" | |
} Else If (LandianTitleAndList = "Red List") { | |
LandianToolBox := "[ssredlist]" . LandianList . "[/ssredlist]" | |
} | |
Clipboard := LandianToolBox | |
GuiControl,, LandianToolBox, %LandianToolBox% | |
Return | |
; clear all textbox | |
ButtonClear: | |
GuiControl,, ArticleID, | |
GuiControl,, Qty, | |
GuiControl,, LandianImage, | |
GuiControl,, LandianThumbImage, | |
GuiControl,, LandianSliderImage, | |
GuiControl,, LandianToolBox, | |
Return | |
; generate thumbnail from clipboard | |
F9:: | |
FileCreateDir, Landian | |
GuiControlGet, ArticleID | |
GuiControlGet, Qty | |
If (!ArticleID) { | |
MsgBox "DO NOT forget to input an article ID." | |
Return | |
} | |
pBitmapClipboard := Gdip_CreateBitmapFromClipboard() | |
If (pBitmapClipboard < 0) { | |
MsgBox "Something wrong with the Clipboard. code" %pBitmapClipboard% "May be no picture on the clipboard?" | |
DllCall("CloseClipboard") | |
Return | |
} | |
ClipWidth := Gdip_GetImageWidth(pBitmapClipboard) | |
ClipHeight := Gdip_GetImageHeight(pBitmapClipboard) | |
ClipRatio := ClipWidth/ClipHeight | |
TargetWidth := 290 | |
TargetHeight := 177 | |
pBitmapTargetImage := Gdip_CreateBitmap(TargetWidth, TargetHeight) | |
pGraphicsTargetImage := Gdip_GraphicsFromImage(pBitmapTargetImage) | |
; We do not need SmoothingMode as we did in previous examples for drawing an image | |
; Instead we must set InterpolationMode. This specifies how a file will be resized (the quality of the resize) | |
; Interpolation mode has been set to HighQualityBicubic = 7 | |
Gdip_SetInterpolationMode(pGraphicsTargetImage, 7) | |
; DrawImage will draw the bitmap we took from the file into the graphics of the bitmap we created | |
; We are wanting to draw the entire image, but at half its size | |
; Coordinates are therefore taken from (0,0) of the source bitmap and also into the destination bitmap | |
; The source height and width are specified, and also the destination width and height (half the original) | |
; Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh, Matrix) | |
; d is for destination and s is for source. We will not talk about the matrix yet (this is for changing colours when drawing) | |
If (Round(TargetWidth*(1/ClipRatio)) < TargetHeight) { | |
Gdip_DrawImage(pGraphicsTargetImage, pBitmapClipboard, 0, (TargetHeight-ClipHeight)//2, TargetWidth, ClipHeight, 0, 0, ClipWidth, ClipHeight) | |
} Else { | |
Gdip_DrawImage(pGraphicsTargetImage, pBitmapClipboard, 0, 0, TargetWidth, Round(TargetWidth*(1/ClipRatio)), 0, 0, ClipWidth, ClipHeight) | |
} | |
; save to file | |
LandianImagesPath := A_ScriptDir . "\Landian\" | |
sOutput := LandianImagesPath . ArticleID . "T.png" | |
Gdip_SaveBitmapToFile(pBitmapTargetImage, sOutput, Quality:=90) | |
; Create a layered window | |
Gui, 2:New, , %sOutput% | |
Gui, Add, Picture, , %sOutput% | |
Gui, Show, NA | |
; The bitmaps can be deleted | |
Gdip_DisposeImage(pBitmapClipboard) | |
Gdip_DisposeImage(pBitmapTargetImage) | |
; The graphics can be deleted | |
Gdip_DeleteGraphics(pGraphicsTargetImage) | |
Return | |
F10:: | |
FileCreateDir, Landian | |
; Check the ArticleID | |
GuiControlGet, ArticleID | |
GuiControlGet, Qty | |
If (!ArticleID) { | |
MsgBox "DO NOT forget to input an article ID." | |
Return | |
} | |
LandianWatermarkFile := "LandianWatermark.png" | |
If !FileExist(LandianWatermarkFile) { | |
MsgBox "Cannot find 'LandianWatermark.png' in the same directory." | |
Return | |
} | |
pBitmapLandianWatermarkFile := Gdip_CreateBitmapFromFile(LandianWatermarkFile) | |
WatermarkWidth := Gdip_GetImageWidth(pBitmapLandianWatermarkFile) | |
WatermarkHeight := Gdip_GetImageHeight(pBitmapLandianWatermarkFile) | |
pBitmapClipboard := Gdip_CreateBitmapFromClipboard() | |
If (pBitmapClipboard < 0) { | |
MsgBox "Something wrong with the Clipboard. code" %pBitmapClipboard% | |
DllCall("CloseClipboard") | |
Return | |
} | |
ClipWidth := Gdip_GetImageWidth(pBitmapClipboard) | |
ClipHeight := Gdip_GetImageHeight(pBitmapClipboard) | |
ClipRatio := ClipWidth/ClipHeight | |
TargetWidth := 751 | |
TargetHeight := Round(TargetWidth*(1/ClipRatio)) | |
pBitmapTargetImage := Gdip_CreateBitmap(TargetWidth, TargetHeight) | |
pGraphicsTargetImage := Gdip_GraphicsFromImage(pBitmapTargetImage) | |
; We do not need SmoothingMode as we did in previous examples for drawing an image | |
; Instead we must set InterpolationMode. This specifies how a file will be resized (the quality of the resize) | |
; Interpolation mode has been set to HighQualityBicubic = 7 | |
Gdip_SetInterpolationMode(pGraphicsTargetImage, 7) | |
; DrawImage will draw the bitmap we took from the file into the graphics of the bitmap we created | |
; We are wanting to draw the entire image, but at half its size | |
; Coordinates are therefore taken from (0,0) of the source bitmap and also into the destination bitmap | |
; The source height and width are specified, and also the destination width and height (half the original) | |
; Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh, Matrix) | |
; d is for destination and s is for source. We will not talk about the matrix yet (this is for changing colours when drawing) | |
If (ClipWidth > TargetWidth) { | |
Gdip_DrawImage(pGraphicsTargetImage, pBitmapClipboard, 0, 0, TargetWidth, TargetHeight, 0, 0, ClipWidth, ClipHeight) | |
} Else { | |
Gdip_DrawImage(pGraphicsTargetImage, pBitmapClipboard, 0, 0, ClipWidth, TargetHeight, 0, 0, ClipWidth, ClipHeight) | |
} | |
Gdip_DrawImage(pGraphicsTargetImage, pBitmapLandianWatermarkFile, TargetWidth-WatermarkWidth-5, TargetHeight-WatermarkHeight-5, WatermarkWidth, WatermarkHeight, 0, 0, WatermarkWidth, WatermarkHeight) | |
; save to file | |
LandianImagesPath := A_ScriptDir . "\Landian\" | |
; To generate a filename according to the ArticleID and Qty | |
If (Qty = 1) { | |
sOutput := LandianImagesPath . ArticleID . ".png" | |
} Else { | |
sOutput := LandianImagesPath . ArticleID . "-1.png" | |
If FileExist(sOutput) { | |
Loop, Files, %LandianImagesPath%\%ArticleID%-?.png | |
{ | |
sOutput := LandianImagesPath . ArticleID . "-" . A_Index+1 . ".png" | |
} | |
} | |
} | |
; Save the modified bitmap to .png file | |
Gdip_SaveBitmapToFile(pBitmapTargetImage, sOutput, Quality:=90) | |
; Create a new window to show the snap | |
Gui, 3:New | |
Gui, Add, Picture, , %sOutput% | |
Gui, Show, NA | |
; The graphics may now be deleted | |
Gdip_DisposeImage(pBitmapClipboard) | |
Gdip_DisposeImage(pBitmapLandianWatermarkFile) | |
Gdip_DisposeImage(pBitmapTargetImage) | |
; The graphics may now be deleted | |
Gdip_DeleteGraphics(pGraphicsTargetImage) | |
Return | |
; On closing the app | |
GuiClose: | |
; Shutdown Gdip | |
Gdip_Shutdown(pToken) | |
ExitApp | |
; Editing for the title | |
:*:;edt::[正在编辑] | |
; Auditing for the title | |
:*:;adt::[待审] | |
; Corner Bracket (U+300C) (U+300D) | |
:*:;cb::「」 | |
Author
zozovo
commented
Jun 8, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment