#include <File.au3>
#include <GDIPlus.au3>
_GDIPlus_Startup()
Global $folder = FileSelectFolder("Select folder with pictures", "", 4) & "\"
Global $outfolder = @ScriptDir & "\Resized"
If @error Then Exit MsgBox(0, "Information", "Nothing selected - closing program", 10)
Global $aFiles = _FileListToArray($folder, "*.???", 0)
For $i = 1 To $aFiles[0]
If StringRegExp($aFiles[$i], "(?i).*\.png|.*\.jpg|.*\.bmp", 0) Then ResizeImage
($folder & $aFiles[$i], 32, 32, $outfolder, -1)
Next
_GDIPlus_Shutdown()
ShellExecute($outfolder)
Exit
;======================================================================================
; Function Name: ResizeImage
; Description: Loads an image and scales it to desired width or height
;
; Parameters: $fImage: image file to be loaded
; $iW: new image width. If $iW = 0 then default values is 96
; $iH: new image height. If $iH = 0 then default values is 96
; $fDestFolder: destination folder where the scaled image should be saved to
; $fExt: image output format (can be jpg, png, bmp, gif, tiff) - default is PNG, -1 to keep extension
; $fPart: filename part to separate it from orignal name. Default is .resized. -> filename.resized.ext
;
; Requirement(s): GDIPlus.au3
; Return Value(s): Success: True, Error: see below
; Error codes: 1: no filename given
; 2: filename doesn't exist
; 3: image couldn't be resized
; 4: resized image couldn't be saved
;
; Author(s): UEZ
; Version: v0.80 Build 2011-08-29 Beta
;=======================================================================================
Func ResizeImage
($fImage, $iW, $iH, $fDestFolder, $fExt = "png", $fPart = ".resized.")
If $fImage = "" Then Return SetError(1, 0, 0)
If Not FileExists($fImage) Then Return SetError(2, 0, 0)
Local $iOutputFormats = "jpg,png,bmp,gif,tif"
If Not StringInStr($iOutputFormats, $fExt) Then
If $fExt <> -1 Then
$fExt = "png"
Else
If Not StringInStr($iOutputFormats, StringRight($fImage, 3)) Then
$fExt = "png"
Else
$fExt = StringRight($fImage, 3)
EndIf
EndIf
EndIf
Local $fName = StringRegExpReplace($fImage, ".*\\(.*).{4}", "$1")
Local $declared = True
If Not $ghGDIPDll Then
_GDIPlus_Startup()
$declared = False
EndIf
Local $hImageFromFile = _GDIPlus_ImageLoadFromFile($fImage)
Local $iWidth = _GDIPlus_ImageGetWidth($hImageFromFile)
Local $iHeight = _GDIPlus_ImageGetHeight($hImageFromFile)
Local $x, $y
If Not $iW And Not $iH Then
$iW = 96
$iH = 96
ElseIf $iW And Not $iH Then
$x = $iW / $iWidth
$iH = Int($iHeight * $x)
ElseIf Not $iW And $iH Then
$y = $iH / $iHeight
$iW = Int($iWidth * $y)
EndIf
Local $hImageThumbnail = DllCall($ghGDIPDll, "uint", "GdipGetImageThumbnail", "handle", $hImageFromFile, "uint", $iW, "uint", $iH, "int*", 0, "ptr", 0, "ptr", 0)
If @error Then
_GDIPlus_ImageDispose($hImageFromFile)
If Not $declared Then _GDIPlus_Shutdown()
Return SetError(3, 0, 0)
EndIf
$hImageThumbnail = $hImageThumbnail[4]
If Not FileExists($fDestFolder) Then DirCreate($fDestFolder)
If $fPart = "" Then $fPart = "."
If Not _GDIPlus_ImageSaveToFile($hImageThumbnail, $fDestFolder & "\" & $fName & $fPart & $fExt) Then
_GDIPlus_ImageDispose($hImageFromFile)
_GDIPlus_ImageDispose($hImageThumbnail)
If Not $declared Then _GDIPlus_Shutdown()
Return SetError(4, 0, 0)
EndIf
_GDIPlus_ImageDispose($hImageFromFile)
_GDIPlus_ImageDispose($hImageThumbnail)
If Not $declared Then _GDIPlus_Shutdown()
Return True
EndFunc