Sign in to follow this  
Followers 0
iamtheky

png resize

3 posts in this topic

this batch resizes pngs in a folder to 32x32, any way to do this and maintain transparency??

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <Array.au3>

Global $pngArray , $pngFolder

$pngFolder = inputbox ("folder name?" , "Type or Copy Folder Name Below")

If FileExists ($pngfolder) Then

$pngArray = _RecFileListToArray($pngFolder, "*.png", 1, 1, 0, 2)

$pngArraynopath = _RecFileListToArray($pngFolder, "*.png", 1, 1, 0, 1)

For $i = 1 to ubound ($pngArray) - 1
tooltip ("resizing " & $i & " of " & ubound ($pngArray) - 1 & " .png files" , 0 , 0 , "PNGresizer")
_ImageResize($pngArray[$i], @ScriptDir & "\Resized_" & $pngArraynopath[$i], 32, 32)
sleep (10)
Next

Else

    msgbox (0, '' , "path does not exist")

EndIf

Exit


; #FUNCTION# =========================================================================================
; Name...........: _ImageResize
; Description....: Resize an image and optionally convert it to the format you want.
; Syntax.........: _ImageResize($sInImage, $sOutImage, $iW, $iH)
; Parameters ....: $sInImage  - Full path to the image to resize / convert.
;                               In types: *.bmp, *.gif, *.ico, *.jpg, *.jpeg, *.png, *.tif, *.tiff
;               $sOutImage - Full path where to save the resized / converted image.
;                               Out types: *.bmp, *.gif, *.jpg, *.jpeg, *.png, *.tif, *.tiff
;               $iW     - Width to resize image to.
;               $iH     - Height to resize image to.
; Return values .: Success  - Return 1 and @error 0
;               Failure - Return 0 and @error 1~5
;                               @error 1 = In File does not exist
;                               @error 2 = In File format not supported
;                               @error 3 = Out File path does not exist
;                               @error 4 = Out file format not supported
;                               @error 5 = Resize Width or Height not an integer
; ====================================================================================================

Func _ImageResize($sInImage, $sOutImage, $iW, $iH)
    ;declaracion de variables
    Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
    Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF"


    If Not FileExists($sInImage) Then Return SetError(1, 0, 0)
    $sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1)))
    If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0)

    ;OutFile path, to use later on.
    $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
    If Not FileExists($sOP) Then Return SetError(3, 0, 0)

    ;OutFile name, to use later on.
    $sOF = StringTrimLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))


    ;OutFile extension , to use for the encoder later on.
    $Ext = StringUpper(StringTrimLeft($sOutImage, StringInStr($sOutImage, ".", 0, -1)))
    If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0)

    If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0)

    ; WinAPI to create blank bitmap at the width and height to put your resized image on.
    $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32)

    ;Start GDIPlus
    _GDIPlus_Startup()

    ;Get the handle of blank bitmap you created above as an image
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

    ;Load the image you want to resize.
    $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)

    ;Get the graphic context of the blank bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)

;im not sure if this is better going here or if its the best form to call it
DllCall($ghGDIPDll, "int", "GdipSetInterpolationMode", "hwnd", $hGraphic, "int", "7")

    ;Draw the loaded image onto the blank bitmap at the size you want
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)


    ;Get the encoder of to save the resized image in the format you want.
    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)

    ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
    Do
        $i += 1
    Until (Not FileExists($sOP & $i & "_" & $sOF))

    ;Prefix the number to the begining of the output filename
    $sOutImage = $sOP & $i & "_" & $sOF

    ;Save the new resized image.
    _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID)

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Return SetError(0, 0, 1)
EndFunc   ;==>_ImageResize

;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

; #INDEX# =======================================================================================================================
; Title .........: _RecFileListToArray
; AutoIt Version : v3.3.1.1 or higher
; Language ......: English
; Description ...: Lists files and\or folders in specified path with optional recursion to defined level and result sorting
; Note ..........:
; Author(s) .....: Melba23
; Remarks .......: - Modified Array.au3 functions - credit: Jos van der Zande, LazyCoder, Tylo, Ultima, SolidSnake and gcriaco
;               - SRE patterns - credit: various forum members and Spiff59 in particular
;               - Despite the name, this UDF is iterative, not recursive
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
; _RecFileListToArray: Lists files and\or folders in a specified path with optional recursion to defined level and result sorting
; ===============================================================================================================================

; #INTERNAL_USE_ONLY#============================================================================================================
; _RFLTA_ListToMask ......; Convert include/exclude lists to SRE format
; _RFLTA_AddToList .......; Add element to list which is resized if necessary
; _RFLTA_AddFileLists ....; Add internal lists after resizing and optional sorting
; _RFLTA_ArraySearch .....; Search array for partial match
; _RFLTA_ArraySort .......; Wrapper for QuickSort function
; _RFLTA_QuickSort .......: Recursive array sort
; _RFLTA_ArrayConcatenate : Join 2 arrays
; _RFLTA_ArrayInsert .....: Insert element into array
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _RecFileListToArray
; Description ...: Lists files and\or folders in a specified path with optional recursion to defined level and result sorting
; Syntax.........: _RecFileListToArray($sPath[, $sInclude_List = "*"[, $iReturn = 0[, $iRecur = 0[, $iSort = 0[, $iReturnPath = 1[, $sExclude_List = ""]]]]]])
; Parameters ....: $sPath - Initial path used to generate filelist.  If path ends in \ then folders will be returned with an ending \
;               $sInclude_List - Optional: filter for included results (default "*"). Multiple filters must be separated by ";"
;               $iReturn - Optional: specifies whether to return files, folders or both
;               |$iReturn = 0 (Default) Return both files and folders
;               |$iReturn = 1 Return files only
;               |$iReturn = 2 Return folders only
;               $iRecur - Optional: specifies whether to search recursively in subfolders and to what level
;               |$iRecur = 1 Search in all subfolders (unlimited recursion)
;               |$iRecur = 0 (Default) Do not search in subfolders
;               |$iRecur = Negative integer - Search in subfolders to specified depth
;               $iSort - Optional: sort ordered in alphabetical and depth order
;               |$iSort = 0 (Default) Not sorted
;               |$iSort = 1 Sorted
;               $iReturnPath - Optional: specifies displayed path of results
;               |$iReturnPath = 0 File/folder name only
;               |$iReturnPath = 1 (Default) Relative to initial path
;               |$iReturnPath = 2 Full path included
;               $sExclude_List - Optional: filter for excluded results (default ""). Multiple filters must be separated by ";"
; Requirement(s).: v3.3.1.1 or higher
; Return values .: Success: One-dimensional array made up as follows:
;               |$array[0] = Number of Files\Folders returned
;               |$array[1] = 1st File\Folder
;               |$array[2] = 2nd File\Folder
;               |...
;               |$array[n] = nth File\Folder
;                   Failure: Null string and @error = 1 with @extended set as follows:
;               |1 = Path not found or invalid
;               |2 = Invalid $sInclude_List
;               |3 = Invalid $iReturn
;               |4 = Invalid $iRecur
;               |5 = Invalid $iSort
;               |6 = Invalid $iReturnPath
;               |7 = Invalid $sExclude_List
;               |8 = No files/folders found
; Author ........: Melba23
; Remarks .......: Compatible with existing _FileListToArray syntax
; Related .......:
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _RecFileListToArray($sInitialPath, $sInclude_List = "*", $iReturn = 0, $iRecur = 0, $iSort = 0, $iReturnPath = 1, $sExclude_List = "")

    Local $asReturnList[100] = [0], $asFileMatchList[100] = [0], $asRootFileMatchList[100] = [0], $asFolderMatchList[100] = [0], $asFolderSearchList[100] = [1]
    Local $sFolderSlash = "", $iMaxLevel, $sInclude_List_Mask, $sExclude_List_Mask, $hSearch, $fFolder, $sRetPath = "", $sCurrentPath, $sName

    ; Check for valid path
    If Not FileExists($sInitialPath) Then Return SetError(1, 1, "")
    ; Check if folders should have trailing \ and ensure that initial path does have one
    If StringRight($sInitialPath, 1) = "\" Then
        $sFolderSlash = "\"
    Else
        $sInitialPath = $sInitialPath & "\"
    EndIf
    ; Add path to folder search list
    $asFolderSearchList[1] = $sInitialPath

    ; Check for valid recur value
    If $iRecur > 1 Or Not IsInt($iRecur) Then Return SetError(1, 4, "")
    ; If required, determine \ count for max recursive level setting
    If $iRecur < 0 Then
        StringReplace($sInitialPath, "\", "", 2)
        $iMaxLevel = @extended - $iRecur
    EndIf

    ; Create Include List mask
    If $sInclude_List = "*" Then
        $sInclude_List_Mask = ".+" ; Set mask to exclude base folder with NULL name
    Else
        If Not _RFLTA_ListToMask($sInclude_List_Mask, $sInclude_List) Then Return SetError(1, 2, "")
    EndIf

    ; Create Exclude List mask
    If $sExclude_List = "" Then
        $sExclude_List_Mask = ":" ; Set unmatchable mask
    Else
        If Not _RFLTA_ListToMask($sExclude_List_Mask, $sExclude_List) Then Return SetError(1, 7, "")
    EndIf

    ; Verify other parameters
    If Not ($iReturn = 0 Or $iReturn = 1 Or $iReturn = 2) Then Return SetError(1, 3, "")
    If Not ($iSort = 0 Or $iSort = 1) Then Return SetError(1, 5, "")
    If Not ($iReturnPath = 0 Or $iReturnPath = 1 Or $iReturnPath = 2) Then Return SetError(1, 6, "")

    ; Search within listed folders
    While $asFolderSearchList[0] > 0

        ; Set path to search
        $sCurrentPath = $asFolderSearchList[$asFolderSearchList[0]]
        ; Reduce folder search list count
        $asFolderSearchList[0] -= 1

        ; Determine return path to add to file/folder name
        Switch $iReturnPath
            ; Case 0 ; Name only
            ; Leave as ""
            Case 1 ;Relative to initial path
                $sRetPath = StringReplace($sCurrentPath, $sInitialPath, "")
            Case 2 ; Full path
                $sRetPath = $sCurrentPath
        EndSwitch

        ; Get search handle
        $hSearch = FileFindFirstFile($sCurrentPath & "*")
        ; If folder empty move to next in list
        If $hSearch = -1 Then
            ContinueLoop
        EndIf

        ; Search folder
        While 1
            $sName = FileFindNextFile($hSearch)
            ; Check for end of folder
            If @error Then
                ExitLoop
            EndIf
            ; Set subfolder flag - @extended set in 3.3.1.1 +
            $fFolder = @extended

            ; If folder then check whether to add to search list
            If $fFolder Then
                Switch $iRecur
                    Case 1 ; Always add
                        _RFLTA_AddToList($asFolderSearchList, $sCurrentPath & $sName & "\")
                    Case 0 ; Never add
                        ; Do nothing
                    Case Else ; Add if max level not exceeded
                        StringReplace($sCurrentPath, "\", "", 0, 2)
                        If @extended < $iMaxLevel Then
                            _RFLTA_AddToList($asFolderSearchList, $sCurrentPath & $sName & "\")
                        EndIf
                EndSwitch
            EndIf

            ; Match name against Include/Exclude masks
            If StringRegExp($sName, $sInclude_List_Mask) And Not StringRegExp($sName, $sExclude_List_Mask) Then

                If $iSort Then ; Save in relevant folders for later sorting

                    If $fFolder Then
                        _RFLTA_AddToList($asFolderMatchList, $sRetPath & $sName & $sFolderSlash)
                    Else
                        ; Select required list for files
                        If $sCurrentPath = $sInitialPath Then
                            _RFLTA_AddToList($asRootFileMatchList, $sRetPath & $sName)
                        Else
                            _RFLTA_AddToList($asFileMatchList, $sRetPath & $sName)
                        EndIf
                    EndIf

                Else ; Save directly in return list

                    ; Check file/folder type against required return value
                    If $fFolder + $iReturn <> 2 Then
                        ; Add final "\" to folders if required
                        If $fFolder Then $sName &= $sFolderSlash
                        _RFLTA_AddToList($asReturnList, $sRetPath & $sName)
                    EndIf

                EndIf
            EndIf
        WEnd

        ; Close current search
        FileClose($hSearch)

    WEnd

    If $iSort Then

        ; Check if any file/folders have been added
        If $asRootFileMatchList[0] = 0 And $asFileMatchList[0] = 0 And $asFolderMatchList[0] = 0 Then Return SetError(1, 8, "")

        Switch $iReturn
            Case 2 ; Folders only
                ; Correctly size folder match list
                ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]
                ; Copy size folder match array
                $asReturnList = $asFolderMatchList
                ; Simple sort list
                _RFLTA_ArraySort($asReturnList)
            Case 1 ; Files only
                If $iReturnPath = 0 Then ; names only so simple sort suffices
                    ; Combine file match lists
                    _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)
                    ; Simple sort combined file list
                    _RFLTA_ArraySort($asReturnList)
                Else
                    ; Combine sorted file match lists
                    _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList, 1)
                EndIf
            Case 0 ; Both files and folders
                If $iReturnPath = 0 Then ; names only so simple sort suffices
                    ; Combine file match lists
                    _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)
                    ; Set correct count for folder add
                    $asReturnList[0] += $asFolderMatchList[0]
                    ; Resize and add file match array
                    ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]
                    _RFLTA_ArrayConcatenate($asReturnList, $asFolderMatchList)
                    ; Simple sort final list
                    _RFLTA_ArraySort($asReturnList)
                Else
                    ; Combine sorted file match lists
                    _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList, 1)
                    ; Add folder count
                    $asReturnList[0] += $asFolderMatchList[0]
                    ; Sort folder match list
                    ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]
                    _RFLTA_ArraySort($asFolderMatchList)

                    ; Now add folders in correct place
                    Local $iLastIndex = UBound($asReturnList)

                    For $i = $asFolderMatchList[0] To 1 Step -1
                        ; Find first filename containing folder name
                        Local $iIndex = _RFLTA_ArraySearch($asReturnList, $asFolderMatchList[$i])
                        If $iIndex = -1 Then
                            ; Empty folder so insert immediately above previous
                            _RFLTA_ArrayInsert($asReturnList, $iLastIndex, $asFolderMatchList[$i])
                        Else
                            ; Insert folder at correct point above files
                            _RFLTA_ArrayInsert($asReturnList, $iIndex, $asFolderMatchList[$i])
                            $iLastIndex = $iIndex
                        EndIf
                    Next
                EndIf
        EndSwitch

    Else ; No sort

        ; Check if any file/folders have been added
        If $asReturnList[0] = 0 Then Return SetError(1, 8, "")

        ; Remove any unused return list elements from last ReDim
        ReDim $asReturnList[$asReturnList[0] + 1]

    EndIf

    Return $asReturnList

EndFunc   ;==>_RecFileListToArray

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _RFLTA_ListToMask
; Description ...: Convert include/exclude lists to SRE format
; Syntax ........: _RFLTA_ListToMask(ByRef $sMask, $sList)
; Parameters ....: $asMask - Include/Exclude mask to create
;               $asList - Include/Exclude list to convert
; Return values .: Success: 1
;               Failure: 0
; Author ........: SRE patterns developed from those posted by various forum members and Spiff59 in particular
; Remarks .......: This function is used internally by _RecFileListToArray
; ===============================================================================================================================
Func _RFLTA_ListToMask(ByRef $sMask, $sList)

    ; Check for invalid characters within list
    If StringRegExp($sList, "\\|/|:|\<|\>|\|") Then Return 0
    ; Strip WS and insert | for ;
    $sList = StringReplace(StringStripWS(StringRegExpReplace($sList, "\s*;\s*", ";"), 3), ";", "|")
    ; Convert to SRE pattern
    $sList = StringReplace(StringReplace(StringRegExpReplace($sList, "(\^|\$|\.)", "\\$1"), "?", "."), "*", ".*?")
    ; Add prefix and suffix
    $sMask =  "(?i)^(" & $sList & ")\z"
    Return 1

EndFunc   ;==>_RFLTA_ListToMask

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _RFLTA_AddToList
; Description ...: Add element to list which is resized if necessary
; Syntax ........: _RFLTA_AddToList(ByRef $asList, $sValue)
; Parameters ....: $asList - List to be added to
;               $sValue - Value to add
; Return values .: None - array modified ByRef
; Author ........: Melba23
; Remarks .......: This function is used internally by _RecFileListToArray
; ===============================================================================================================================
Func _RFLTA_AddToList(ByRef $asList, $sValue)

    ; Increase list count
    $asList[0] += 1
    ; Double list size if too small (fewer ReDim needed)
    If UBound($asList) <= $asList[0] Then ReDim $asList[UBound($asList) * 2]
    ; Add value
    $asList[$asList[0]] = $sValue

EndFunc   ;==>_RFLTA_AddToList

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _RFLTA_AddFileLists
; Description ...: Add internal lists after resizing and optional sorting
; Syntax ........: _RFLTA_AddFileLists(ByRef $asTarget, $asSource_1, $asSource_2[, $iSort = 0])
; Parameters ....: $asReturnList - Base list
;               $asRootFileMatchList - First list to add
;               $asFileMatchList - Second list to add
;               $iSort - (Optional) Whether to sort lists before adding
;               |$iSort = 0 (Default) No sort
;               |$iSort = 1 Sort in descending alphabetical order
; Return values .: None - array modified ByRef
; Author ........: Melba23
; Remarks .......: This function is used internally by _RecFileListToArray
; ===============================================================================================================================
Func _RFLTA_AddFileLists(ByRef $asTarget, $asSource_1, $asSource_2, $iSort = 0)

    ; Correctly size root file match array
    ReDim $asSource_1[$asSource_1[0] + 1]
    ; Simple sort root file match array if required
    If $iSort = 1 Then _RFLTA_ArraySort($asSource_1)
    ; Copy root file match array
    $asTarget = $asSource_1
    ; Add file match count
    $asTarget[0] += $asSource_2[0]
    ; Correctly size file match array
    ReDim $asSource_2[$asSource_2[0] + 1]
    ; Simple sort file match array if required
    If $iSort = 1 Then _RFLTA_ArraySort($asSource_2)
    ; Add file match array
    _RFLTA_ArrayConcatenate($asTarget, $asSource_2)

EndFunc   ;==>_RFLTA_AddFileLists

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _RFLTA_ArraySearch
; Description ...: Search array downwards for partial match
; Syntax ........: _RFLTA_ArraySearch(Const ByRef $avArray, $vValue)
; Parameters ....: $avArray - Array to search
;               $vValue - PValue to search for
; Return values .: Success: Index of array in which element was found
;               Failure: returns -1
; Author ........: SolidSnake, gcriaco, Ultima
; Modified.......: Melba23
; Remarks .......: This function is used internally by _RecFileListToArray
; ===============================================================================================================================
Func _RFLTA_ArraySearch(Const ByRef $avArray, $vValue)

    For $i = 1 To UBound($avArray) - 1
        If StringInStr($avArray[$i], $vValue) > 0 Then Return $i
    Next
    Return -1

EndFunc   ;==>_RFLTA_ArraySearch

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _RFLTA_ArraySort
; Description ...: Wrapper for QuickSort function
; Syntax ........: _RFLTA_ArraySort(ByRef $avArray)
; Parameters ....: $avArray - Array to sort
;               $pNew_WindowProc - Pointer to new WindowProc
; Return values .: None - array modified ByRef
; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima
; Modified.......: Melba23
; Remarks .......: This function is used internally by _RecFileListToArray
; ===============================================================================================================================
Func _RFLTA_ArraySort(ByRef $avArray)

    Local $iStart = 1, $iEnd = UBound($avArray) - 1
    _RFLTA_QuickSort($avArray, $iStart, $iEnd)

EndFunc   ;==>_RFLTA_ArraySort

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _RFLTA_QuickSort
; Description ...: Recursive array sort
; Syntax ........: _RFLTA_QuickSort(ByRef $avArray, ByRef $iStart, ByRef $iEnd)
; Parameters ....: $avArray - Array to sort in descending alphabetical order
;               $iStart - Start index
;               $iEnd - End index
; Return values .: None - array modified ByRef
; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima
; Modified.......: Melba23
; Remarks .......: This function is used internally by _RFLTA_ArraySort
; ===============================================================================================================================
Func _RFLTA_QuickSort(ByRef $avArray, ByRef $iStart, ByRef $iEnd)

    Local $vTmp
    If ($iEnd - $iStart) < 15 Then
        Local $i, $j, $vCur
        For $i = $iStart + 1 To $iEnd
            $vTmp = $avArray[$i]
            If IsNumber($vTmp) Then
                For $j = $i - 1 To $iStart Step -1
                    $vCur = $avArray[$j]
                    If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur) >= 0) Then ExitLoop
                    $avArray[$j + 1] = $vCur
                Next
            Else
                For $j = $i - 1 To $iStart Step -1
                    If (StringCompare($vTmp, $avArray[$j]) >= 0) Then ExitLoop
                    $avArray[$j + 1] = $avArray[$j]
                Next
            EndIf
            $avArray[$j + 1] = $vTmp
        Next
        Return
    EndIf
    Local $L = $iStart, $R = $iEnd, $vPivot = $avArray[Int(($iStart + $iEnd) / 2)], $fNum = IsNumber($vPivot)
    Do
        If $fNum Then
            While ($avArray[$L] < $vPivot And IsNumber($avArray[$L])) Or (Not IsNumber($avArray[$L]) And StringCompare($avArray[$L], $vPivot) < 0)
                $L += 1
            WEnd
            While ($avArray[$R] > $vPivot And IsNumber($avArray[$R])) Or (Not IsNumber($avArray[$R]) And StringCompare($avArray[$R], $vPivot) > 0)
                $R -= 1
            WEnd
        Else
            While (StringCompare($avArray[$L], $vPivot) < 0)
                $L += 1
            WEnd
            While (StringCompare($avArray[$R], $vPivot) > 0)
                $R -= 1
            WEnd
        EndIf
        If $L <= $R Then
            $vTmp = $avArray[$L]
            $avArray[$L] = $avArray[$R]
            $avArray[$R] = $vTmp
            $L += 1
            $R -= 1
        EndIf
    Until $L > $R
    _RFLTA_QuickSort($avArray, $iStart, $R)
    _RFLTA_QuickSort($avArray, $L, $iEnd)

EndFunc   ;==>_RFLTA_QuickSort

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _RFLTA_ArrayConcatenate
; Description ...: Joins 2 arrays
; Syntax ........: _RFLTA_ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource)
; Parameters ....: $avArrayTarget - Base array
;               $avArraySource - Array to add from element 1 onwards
; Return values .: None - array modified ByRef
; Author ........: Ultima
; Modified.......: Melba23
; Remarks .......: This function is used internally by _RecFileListToArray
; ===============================================================================================================================
Func _RFLTA_ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource)

    Local $iUBoundTarget = UBound($avArrayTarget) - 1, $iUBoundSource = UBound($avArraySource)
    ReDim $avArrayTarget[$iUBoundTarget + $iUBoundSource]
    For $i = 1 To $iUBoundSource - 1
        $avArrayTarget[$iUBoundTarget + $i] = $avArraySource[$i]
    Next

EndFunc   ;==>_RFLTA_ArrayConcatenate

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _RFLTA_ArrayInsert
; Description ...: Insert element into array
; Syntax ........: _RFLTA_ArrayInsert(ByRef $avArray, $iElement, $vValue = "")
; Parameters ....: $avArray - Array to modify
;               $iElement - Index position for insertion
;               $vValue - Value to insert
; Return values .: None - array modified ByRef
; Author ........: Jos van der Zande, Ultima
; Modified.......: Melba23
; Remarks .......: This function is used internally by _RecFileListToArray
; ===============================================================================================================================
Func _RFLTA_ArrayInsert(ByRef $avArray, $iElement, $vValue = "")

    Local $iUBound = UBound($avArray) + 1
    ReDim $avArray[$iUBound]
    For $i = $iUBound - 1 To $iElement + 1 Step -1
        $avArray[$i] = $avArray[$i - 1]
    Next
    $avArray[$iElement] = $vValue

EndFunc   ;==>_RFLTA_ArrayInsert

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

#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)
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

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

i do love that german engineering. The new IPB style not so much.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0