Skip to content

Instantly share code, notes, and snippets.

@maz-1
Last active June 23, 2017 10:05
Show Gist options
  • Save maz-1/aeee6fcca84c6f8e9010a856cb796f48 to your computer and use it in GitHub Desktop.
Save maz-1/aeee6fcca84c6f8e9010a856cb796f48 to your computer and use it in GitHub Desktop.
#NoTrayIcon
#NoEnv
#singleinstance,force
modified=20161122
filename1=Generate thumbnail By Maz-1 (maz_1@foxmail.com)
SetWorkingDir %A_ScriptDir%
StringCaseSense, Off
#Include Gdip.ahk
binpath=%A_ScriptDir%\bin\
GDIPToken := Gdip_Startup()
Small_Width = 480
Small_Height = 270
Big_Width = 984
Big_Height = 328
fName = %1%
If FileExist(fName)
{
To_Thumb(fName)
exitapp
}
w_width = 280
w_height = 200
w_x := A_ScreenWidth - w_width - 10
w_y := A_ScreenHeight - w_height - 100
g_width := w_width - 20
Gui,2: Font, default, FixedSys
Gui,2:+ToolWindow
Gui,2:Show, x%w_x% y%w_y% w%w_width% h%w_height% ,%Filename1%
Gui,2:add,checkbox , x10 y10 w%g_width% h20 vF2,Keep window open
Gui,2:add,text , x10 y30 w%g_width% h165 vF1,`nDrag to here
return
2Guiclose:
;Gdip_Shutdown(GDIPToken)
exitapp
$Esc::
exitapp
2GuiDropFiles:
GuiControl,2:,F1
Loop, parse, A_GuiEvent, `n
GuiControl,2:,F1,%A_LoopField%
Gui,2:submit,nohide
guicontrolget,F1
guicontrolget,F2
if (To_Thumb(F1) =1 and not F2)
exitapp
Return
Get_Size(fullpath, ByRef width, ByRef height, ByRef ratio)
{
Global GDIPToken
SplitPath, fullpath, , , ext
pBM := Gdip_CreateBitmapFromFile(fullpath)
width:= Gdip_GetImageWidth(pBM)
height:= Gdip_GetImageHeight(pBM)
ratio := width/height
Gdip_DisposeImage(pBM)
}
Convert_Resize(source_file,out_file,width,height)
{
Global GDIPToken
pBitmapFile := Gdip_CreateBitmapFromFile(source_file)
In_Width := Gdip_GetImageWidth(pBitmapFile), In_Height := Gdip_GetImageHeight(pBitmapFile)
pBitmap := Gdip_CreateBitmap(width, height)
G := Gdip_GraphicsFromImage(pBitmap)
Gdip_DrawImage(G, pBitmapFile, 0, 0, width, height, 0, 0, In_Width, In_Height)
Gdip_SaveBitmapToFile(pBitmap, out_file)
Gdip_DisposeImage(pBitmapFile)
Gdip_DisposeImage(pBitmap)
Gdip_DeleteGraphics(G)
}
To_Thumb(fullpath)
{
Global Small_Width
Global Small_Height
Global Big_Width
Global Big_Height
Global GDIPToken
GetKeyState, AltState, Alt
SplitPath, fullpath, name, dir, ext, name_no_ext, drive
If Ext Not In jpg,jpeg,bmp,png,tif,tiff
{
return 0
}
pOrigFile := Gdip_CreateBitmapFromFile(fullpath)
Get_Size(pOrigFile, width, height, ratio)
If AltState = D
{
;if (ratio > Big_Width/Big_Height)
; Convert_Resize(pOrigFile, dir . "\" . name_no_ext . "_big.jpg", Big_Height*ratio, Big_Height)
;else
; Convert_Resize(pOrigFile, dir . "\" . name_no_ext . "_big.jpg", Big_Width, Big_Width/ratio)
;FileDelete, %fullpath%
;FileMove, %dir%\%name_no_ext%_big.jpg, %dir%\%name_no_ext%.jpg
Gdip_DisposeImage(pOrigFile)
Remove_Border(fullpath)
return 1
}
if (ratio > 1.44)
{
if (ratio > Small_Width/Small_Height)
Convert_Resize(pOrigFile, dir . "\" . name_no_ext . "_small.jpg", Small_Height*ratio, Small_Height)
else
Convert_Resize(pOrigFile, dir . "\" . name_no_ext . "_small.jpg", Small_Width, Small_Width/ratio)
}
if (ratio < 1.6 and width <> Small_Width and height <> Small_Height)
{
;pOrigFile := Gdip_CreateBitmapFromFile(fullpath)
;In_Width := Gdip_GetImageWidth(pOrigFile), In_Height := Gdip_GetImageHeight(pOrigFile)
pBGUnblurred := Gdip_CreateBitmap(Small_Width, Small_Height)
G1 := Gdip_GraphicsFromImage(pBGUnblurred)
Gdip_DrawImage(G1, pOrigFile, 0, 0, Small_Width, Small_Height, 0, 0, width, height)
pBGBlurred := Gdip_BlurBitmap(pBGUnblurred, 50)
FG_Width := Small_Height*(width/height)
G2 := Gdip_GraphicsFromImage(pBGBlurred)
X1 := Ceil((Small_Width-FG_Width)/2)
Gdip_DrawImage(G2, pOrigFile, X1, 0, FG_Width, Small_Height, 0, 0, width, height)
Gdip_SaveBitmapToFile(pBGBlurred, dir . "\" . name_no_ext . "_small2.jpg")
;Gdip_DisposeImage(pOrigFile)
Gdip_DisposeImage(pBGBlurred)
Gdip_DisposeImage(pBGUnblurred)
Gdip_DeleteGraphics(G1)
Gdip_DeleteGraphics(G2)
}
if (width > Big_Width and height > Big_Height )
{
if (ratio > Big_Width/Big_Height)
Convert_Resize(pOrigFile, dir . "\" . name_no_ext . "_big.jpg", Big_Height*ratio, Big_Height)
else
Convert_Resize(pOrigFile, dir . "\" . name_no_ext . "_big.jpg", Big_Width, Big_Width/ratio)
}
If (ext <> "jpg")
{
Convert_Resize(pOrigFile, dir . "\" . name_no_ext . ".jpg", width, height)
Gdip_DisposeImage(pOrigFile)
FileDelete, %fullpath%
}
Else
Gdip_DisposeImage(pOrigFile)
FileDelete, %A_Temp%\*.bmp
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment