#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=AutoItv11.ico #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_Comment=Convert and resize from/to JPG, BMP, GIF, PNG,... #AutoIt3Wrapper_Res_Description=Convert and resize from/to JPG, BMP, GIF, PNG,... #AutoIt3Wrapper_Res_Fileversion=2.0.0.0 #AutoIt3Wrapper_Res_ProductName=Pics Converter V2 #AutoIt3Wrapper_Res_ProductVersion=2.0.0.0 #AutoIt3Wrapper_Res_CompanyName=cramaboule.com #AutoIt3Wrapper_Run_Tidy=y #Tidy_Parameters=/reel #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/mo #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.16.0 Author: Marc Arm Date: October 2009 V1 Script Function: 'Pics Converter V2 in Pure AutoIt' made by Cramaboule July 2023 Thanks to AdmiralAlkex for his help ! (on V1) Convert from/to JPG, BMP, GIF, PNG ,...!!! Enjoy ! Bug: To Do: Nothing V2.0.0.0 07.07.2023: Resizing fonction V1.2 bugs fixed V1.1 added new features V1.0 first realese #ce ---------------------------------------------------------------------------- #include #include #include #include #include #include #include #include #include #include #include #include 'ExtMsgBox.au3' $head = "Pics Conversion V2.0" Local $Param = 0, $Decoder, $InDecoder[1][10], $ToCombo, $OldOutEncoder, $Oldpxpercent, $OldValSlider = '0', $OldJPGQuality = '100', $OldHeight, $Oldwidth, $OldCheckRatio Dim $aInterpolation[2][7] = [[$GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBILINEAR, $GDIP_INTERPOLATIONMODE_NEARESTNEIGHBOR, $GDIP_INTERPOLATIONMODE_BICUBIC, $GDIP_INTERPOLATIONMODE_BILINEAR, $GDIP_INTERPOLATIONMODE_HIGHQUALITY, $GDIP_INTERPOLATIONMODE_LOWQUALITY], ['Bicubic HQ (default)', 'Nearest neighbor', 'Bilinear HQ', 'Bicubic (low)', 'Bilinear (low)', 'High-quality', 'Low-quality']] _GDIPlus_Startup() $testBMP = _ScreenCapture_Capture("", 0, 0, 1, 1) $hImage = _GDIPlus_BitmapCreateFromHBITMAP($testBMP) $Decoder = _GDIPlus_Decoders() _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($testBMP) _GDIPlus_Shutdown() For $i = 1 To $Decoder[0][0] ReDim $InDecoder[$Decoder[0][0] + 1][10] $Split = StringSplit($Decoder[$i][6], ";") For $j = 1 To $Split[0] $ToCombo &= StringTrimLeft($Split[$j], 2) & "|" Next Next ;ConsoleWrite($ToCombo & @CRLF) $Conv = GUICreate($head, 555, 210, -1, -1) $Group1 = GUICtrlCreateGroup(" Input ", 5, 5, 140, 145) $InputEncoder = GUICtrlCreateCombo("", 15, 120, 120, 25) GUICtrlSetData(-1, $ToCombo) $InputFolder = GUICtrlCreateInput("Input Folder", 15, 30, 120, 21) $BrowseInput = GUICtrlCreateButton("Browse...", 30, 55, 75, 25, $WS_GROUP) $Label2 = GUICtrlCreateLabel("Convert from:", 15, 95, 67, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group4 = GUICtrlCreateGroup(" Resize ", 155, 5, 140, 145) $Resizing = GUICtrlCreateCheckbox("Resizing", 160, 20, 55, 25) $pxpercent = GUICtrlCreateCombo('px', 230, 22, 40, 25) GUICtrlSetData(-1, '%') $Ratio = GUICtrlCreateCheckbox("Keep aspect ratio", 170, 45, 115, 25) GUICtrlSetState(-1, $GUI_CHECKED) $Width = GUICtrlCreateInput("", 160, 70, 49, 21) $Label4 = GUICtrlCreateLabel("px", 210, 75, 15, 17) $Height = GUICtrlCreateInput("", 225, 70, 49, 21) $Label5 = GUICtrlCreateLabel("px", 275, 75, 15, 17) $Label3 = GUICtrlCreateLabel("Interpolation mode:", 168, 96, 104, 17) $Interpolation = GUICtrlCreateCombo($aInterpolation[1][0], 165, 120, 120, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, $aInterpolation[1][1] & "|" & $aInterpolation[1][2] & "|" & $aInterpolation[1][3] & "|" & $aInterpolation[1][4] & "|" & $aInterpolation[1][5] & "|" & $aInterpolation[1][6]) GUICtrlSetState($Ratio, $GUI_DISABLE) GUICtrlSetState($Width, $GUI_DISABLE) GUICtrlSetState($Label4, $GUI_DISABLE) GUICtrlSetState($Height, $GUI_DISABLE) GUICtrlSetState($Label5, $GUI_DISABLE) GUICtrlSetState($Label3, $GUI_DISABLE) GUICtrlSetState($Interpolation, $GUI_DISABLE) GUICtrlSetState($pxpercent, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup(" Output ", 305, 5, 140, 145) $OutputEncoder = GUICtrlCreateCombo("JPG", 315, 120, 120, 25) GUICtrlSetData(-1, "BMP|GIF|PNG") $OutputFolder = GUICtrlCreateInput("Output Folder", 320, 30, 120, 21) $BrowseOutput = GUICtrlCreateButton("Browse...", 340, 55, 75, 25, $WS_GROUP) $Label1 = GUICtrlCreateLabel("Convert to:", 325, 95, 56, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup(" JPG Quality ", 455, 5, 90, 145) $Slider = GUICtrlCreateSlider(500, 20, 35, 125, BitOR($TBS_VERT, $TBS_TOP, $TBS_LEFT)) $JPGQlty = GUICtrlCreateInput("100", 470, 75, 30, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $GO = GUICtrlCreateButton("Convert", 177, 160, 200, 40, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $OutEncoder = GUICtrlRead($OutputEncoder) $sPxpercent = GUICtrlRead($pxpercent) $ValSlider = GUICtrlRead($Slider) $JPGQuality = GUICtrlRead($JPGQlty) $iHeight = GUICtrlRead($Height) $iWidth = GUICtrlRead($Width) $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg = $BrowseInput $InFold = FileSelectFolder("Choose a folder", "", 7) If $InFold <> "" Then GUICtrlSetData($InputFolder, $InFold) GUICtrlSetData($OutputFolder, $InFold) EndIf Case $nMsg = $BrowseOutput $OutFold = FileSelectFolder("Choose a folder", "", 7) If $OutFold <> "" Then GUICtrlSetData($OutputFolder, $OutFold) EndIf Case $nMsg = $GO $InPath = GUICtrlRead($InputFolder) $OutPath = GUICtrlRead($OutputFolder) $InEncoder = GUICtrlRead($InputEncoder) $OutEncoder = GUICtrlRead($OutputEncoder) If StringInStr($InPath, "\") = 0 Then _ExtMsgBox(16, 0, "Caution!", "Please select a folder!", 0, $Conv) ElseIf ($InEncoder = "") Or ($InEncoder = $OutEncoder And $OutEncoder <> "JPG" And Not (_IsChecked($Resizing))) Then _ExtMsgBox(16, 0, "Caution!", "Please choose different encoder/decoder or enable resizing", 0, $Conv) ElseIf GUICtrlRead($Width) = '' And GUICtrlRead($Height) = '' And _IsChecked($Resizing) Then _ExtMsgBox(16, 0, "Caution!", "Width and/or height cannot be empty", 0, $Conv) Else ; do the conversion process... ; do the progress bar GUI $aPos = WinGetPos($Conv) $Form1 = GUICreate("", 420, 100, ($aPos[0] + ($aPos[2] / 2)) - 210, ($aPos[1] + ($aPos[3] / 2)) - 70, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOOLWINDOW, $Conv) $ProgFile = GUICtrlCreateProgress(10, 10, 400, 15, $PBS_SMOOTH) $ProgAll = GUICtrlCreateProgress(10, 60, 400, 15, $PBS_SMOOTH) $Label1 = GUICtrlCreateLabel("", 10, 80, 400, 17) $Label2 = GUICtrlCreateLabel("", 10, 30, 400, 17) GUISetState(@SW_SHOW) ; If $OutEncoder = "JPG" Then ; Set JPG quality $TParam = _GDIPlus_ParamInit(1) $Datas = DllStructCreate("int Quality") DllStructSetData($Datas, "Quality", $JPGQuality) _GDIPlus_ParamAdd($TParam, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($Datas)) $Param = DllStructGetPtr($TParam) EndIf ; If _IsChecked($Resizing) Then For $j = 0 To UBound($aInterpolation, 2) - 1 ; get the interpolation Mode according to the ComboBox If GUICtrlRead($Interpolation) = $aInterpolation[1][$j] Then $iInterpolation = $aInterpolation[0][$j] EndIf Next EndIf ;process itself $FileList = _FileListToArray($InPath, "*." & $InEncoder, 1) If @error <> 0 Then _ExtMsgBox(16, 0, "Caution!", "No files found or invalid path!", 0, $Conv) Else _GDIPlus_Startup() For $i = 1 To $FileList[0] GUICtrlSetData($ProgFile, 0) GUICtrlSetData($ProgAll, ($i / $FileList[0]) * 100) GUICtrlSetData($Label2, $InPath & "\" & $FileList[$i]) GUICtrlSetData($Label1, $i & " / " & $FileList[0]) $hImage = _GDIPlus_ImageLoadFromFile($InPath & "\" & $FileList[$i]) GUICtrlSetData($ProgFile, 10) If _IsChecked($Resizing) Then ; resizing $aDim = _GDIPlus_ImageGetDimension($hImage) GUICtrlSetData($ProgFile, 20) $iWidthIm = $aDim[0] $iHeightIm = $aDim[1] If _IsChecked($Ratio) Then ;ratio checked $fRatio = $iWidthIm / $iHeightIm ; width / height If GUICtrlRead($pxpercent) = 'px' Then ; px with ratio If GUICtrlRead($Width) <> '' Then $iWidth = GUICtrlRead($Width) $iHeight = Round(GUICtrlRead($Width) / $fRatio) Else $iWidth = Round(GUICtrlRead($Height) * $fRatio) $iHeight = GUICtrlRead($Height) EndIf EndIf Else ;ratio Not checked If GUICtrlRead($pxpercent) = 'px' Then ; px in no ratio $iWidth = GUICtrlRead($Width) $iHeight = GUICtrlRead($Height) EndIf EndIf If GUICtrlRead($pxpercent) = '%' Then ; pourcent $iHeight = Round($iHeightIm * (GUICtrlRead($Height) / 100)) $iWidth = Round($iWidthIm * (GUICtrlRead($Width) / 100)) EndIf $hImage = _GDIPlus_ImageResize($hImage, $iWidth, $iHeight, $iInterpolation) ;resize image GUICtrlSetData($ProgFile, 40) EndIf $clsid = _GDIPlus_EncodersGetCLSID($OutEncoder) GUICtrlSetData($ProgFile, 60) _GDIPlus_ImageSaveToFileEx($hImage, StringReplace($OutPath & "\" & $FileList[$i], "." & $InEncoder, "." & $OutEncoder), $clsid, $Param) GUICtrlSetData($ProgFile, 80) FileSetTime(StringReplace($OutPath & "\" & $FileList[$i], "." & $InEncoder, "." & $OutEncoder), FileGetTime($InPath & "\" & $FileList[$i], 0, 1), 0) FileSetTime(StringReplace($OutPath & "\" & $FileList[$i], "." & $InEncoder, "." & $OutEncoder), FileGetTime($InPath & "\" & $FileList[$i], 1, 1), 1) GUICtrlSetData($ProgFile, 100) Next _GDIPlus_Shutdown() _ExtMsgBox(64, 0, "Done!", "Done!", 0, $Conv) EndIf GUISetState(@SW_HIDE, $Form1) EndIf Case $OutEncoder <> $OldOutEncoder If $OutEncoder <> "JPG" Then GUICtrlSetState($Group3, $GUI_DISABLE) GUICtrlSetState($Slider, $GUI_DISABLE) GUICtrlSetState($JPGQlty, $GUI_DISABLE) Else GUICtrlSetState($Group3, $GUI_ENABLE) GUICtrlSetState($Slider, $GUI_ENABLE) GUICtrlSetState($JPGQlty, $GUI_ENABLE) EndIf $OldOutEncoder = $OutEncoder Case $ValSlider <> $OldValSlider GUICtrlSetData($JPGQlty, 100 - $ValSlider) $OldValSlider = $ValSlider Case $JPGQuality <> $OldJPGQuality $JPGQuality = _checkValue($JPGQuality) GUICtrlSetData($JPGQlty, $JPGQuality) GUICtrlSetData($Slider, 100 - $JPGQuality) $OldJPGQuality = $JPGQuality Case $nMsg = $Resizing If _IsChecked($Resizing) Then GUICtrlSetState($Ratio, $GUI_ENABLE) GUICtrlSetState($Width, $GUI_ENABLE) GUICtrlSetState($Label4, $GUI_ENABLE) GUICtrlSetState($Height, $GUI_ENABLE) GUICtrlSetState($Label5, $GUI_ENABLE) GUICtrlSetState($Label3, $GUI_ENABLE) GUICtrlSetState($Interpolation, $GUI_ENABLE) GUICtrlSetState($pxpercent, $GUI_ENABLE) Else GUICtrlSetState($Ratio, $GUI_DISABLE) GUICtrlSetState($Width, $GUI_DISABLE) GUICtrlSetState($Label4, $GUI_DISABLE) GUICtrlSetState($Height, $GUI_DISABLE) GUICtrlSetState($Label5, $GUI_DISABLE) GUICtrlSetState($Label3, $GUI_DISABLE) GUICtrlSetState($Interpolation, $GUI_DISABLE) GUICtrlSetState($pxpercent, $GUI_DISABLE) EndIf Case $sPxpercent <> $Oldpxpercent If $sPxpercent = 'px' Then GUICtrlSetData($Label4, 'px') GUICtrlSetData($Label5, 'px') GUICtrlSetData($Width, '') GUICtrlSetData($Height, '') Else GUICtrlSetData($Label4, '%') GUICtrlSetData($Label5, '%') GUICtrlSetData($Width, '100') GUICtrlSetData($Height, '100') EndIf $Oldpxpercent = $sPxpercent Case (($iWidth <> $Oldwidth Or $iHeight <> $OldHeight) And _IsChecked($Ratio) And GUICtrlRead($pxpercent) = '%') If $iWidth <> $Oldwidth Then $iWidth = _checkValue($iWidth) $iHeight = $iWidth Else $iHeight = _checkValue($iHeight) $iWidth = $iHeight EndIf GUICtrlSetData($Width, $iHeight) GUICtrlSetData($Height, $iWidth) $Oldwidth = $iWidth $OldHeight = $iHeight Case (($iWidth <> $Oldwidth Or $iHeight <> $OldHeight) And Not (_IsChecked($Ratio)) And GUICtrlRead($pxpercent) = '%') If $iWidth <> $Oldwidth Then $iWidth = _checkValue($iWidth) GUICtrlSetData($Width, $iWidth) Else $iHeight = _checkValue($iHeight) GUICtrlSetData($Height, $iHeight) EndIf $Oldwidth = $iWidth $OldHeight = $iHeight Case _IsChecked($Ratio) <> $OldCheckRatio And GUICtrlRead($pxpercent) = '%' GUICtrlSetData($Height, $iWidth) $OldCheckRatio = _IsChecked($Ratio) $Oldwidth = $iWidth $OldHeight = $iHeight Case Not (_IsChecked($Ratio)) <> $OldCheckRatio And GUICtrlRead($pxpercent) = 'px' If GUICtrlRead($Width) = '' Then GUICtrlSetData($Width, '100') If GUICtrlRead($Height) = '' Then GUICtrlSetData($Height, '100') $OldCheckRatio = Not (_IsChecked($Ratio)) EndSelect WEnd Func _checkValue($iValue) If $iValue > 100 Then $iValue = 100 If $iValue < 1 Then $iValue = 1 Return $iValue EndFunc ;==>_checkValue Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked