Pics Converter


SUBMITTED BY: Guest

DATE: May 28, 2013, 6:18 a.m.

FORMAT: Text only

SIZE: 6.8 kB

HITS: 2058

  1. #cs
  2. 'Pics Converter in Pure AutoIt' made by Cramaboule October 09
  3. Thanks to AdmiralAlkex for his help !
  4. Convert from/to JPG, BMP, GIF, PNG ,...!!!
  5. Enjoy !
  6. - To Do:
  7. - autodetect input type -> Done!!!
  8. - set output file time according to input one -> Done!!!
  9. - for JPG new option for "quality" -> Done!!!
  10. - remove Sleep(10) from FOR/NEXT loop -> Done!!!
  11. V1.0 first realese
  12. V1.1 added new features
  13. V1.2 bugs fixed
  14. #ce
  15. #include <ScreenCapture.au3>
  16. #include <GDIPlus.au3>
  17. #Include <File.au3>
  18. #include <ProgressConstants.au3>
  19. #include <GUIConstantsEx.au3>
  20. #include <WindowsConstants.au3>
  21. #include <SliderConstants.au3>
  22. $head = "Pics Conversion V1.2"
  23. Local $Param=0 , $Decoder, $InDecoder[1][10], $ToCombo
  24. _GDIPlus_Startup ()
  25. $testBMP = _ScreenCapture_Capture ("", 0, 0, 1, 1)
  26. $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($testBMP)
  27. $Decoder = _GDIPlus_Decoders()
  28. _GDIPlus_ImageDispose ($hImage)
  29. _WinAPI_DeleteObject ($testBMP)
  30. _GDIPlus_ShutDown ()
  31. For $i = 1 To $Decoder[0][0]
  32. ReDim $InDecoder[$Decoder[0][0]+1][10]
  33. $Split = StringSplit($Decoder[$i][6],";")
  34. For $j = 1 to $Split[0]
  35. $ToCombo &= StringTrimLeft($Split[$j],2)& "|"
  36. Next
  37. Next
  38. ;ConsoleWrite($ToCombo & @CRLF)
  39. $Conv = GUICreate($head, 400, 210, -1, -1)
  40. $Group1 = GUICtrlCreateGroup("Input", 5, 5, 140, 145)
  41. $InputEncoder = GUICtrlCreateCombo("", 15, 120, 110, 25)
  42. GUICtrlSetData(-1, $ToCombo)
  43. $InputFolder = GUICtrlCreateInput("Input Folder", 15, 30, 120, 21)
  44. $BrowseInput = GUICtrlCreateButton("Browse...", 30, 55, 75, 25, $WS_GROUP)
  45. $Label2 = GUICtrlCreateLabel("Convert from:", 15, 95, 67, 17)
  46. GUICtrlCreateGroup("", -99, -99, 1, 1)
  47. $Group2 = GUICtrlCreateGroup("Output", 155, 5, 140, 145)
  48. $OutputEncoder = GUICtrlCreateCombo("JPG", 170, 120, 110, 25)
  49. GUICtrlSetData(-1, "BMP|GIF|PNG")
  50. $OutputFolder = GUICtrlCreateInput("Output Folder", 165, 30, 120, 21)
  51. $BrowseOutput = GUICtrlCreateButton("Browse...", 185, 55, 75, 25, $WS_GROUP)
  52. $Label1 = GUICtrlCreateLabel("Convert to:", 170, 95, 56, 17)
  53. GUICtrlCreateGroup("", -99, -99, 1, 1)
  54. $GO = GUICtrlCreateButton("Convert", 100, 160, 200, 40, $WS_GROUP)
  55. $Group3 = GUICtrlCreateGroup(" JPG Quality ", 305, 5, 90, 145)
  56. $Slider = GUICtrlCreateSlider(350, 20, 35, 125, BitOR($TBS_VERT,$TBS_TOP,$TBS_LEFT))
  57. $JPGQlty = GUICtrlCreateInput("100", 315, 75, 30, 21)
  58. GUICtrlCreateGroup("", -99, -99, 1, 1)
  59. GUISetState(@SW_SHOW)
  60. $OldOutEncoder=""
  61. $OldValSlider="0"
  62. $OldJPGQuality="100"
  63. While 1
  64. $OutEncoder = GUICtrlRead ($OutputEncoder)
  65. $ValSlider = GUICtrlRead ($Slider)
  66. $JPGQuality = GUICtrlRead($JPGQlty)
  67. $nMsg = GUIGetMsg()
  68. Select
  69. Case $nMsg=$GUI_EVENT_CLOSE
  70. Exit
  71. Case $nMsg= $BrowseInput
  72. $InFold = FileSelectFolder("Choose a folder", "",7)
  73. If $InFold <> "" Then
  74. GUICtrlSetData($InputFolder, $InFold)
  75. GUICtrlSetData($OutputFolder, $InFold)
  76. EndIf
  77. Case $nMsg= $BrowseOutput
  78. $OutFold = FileSelectFolder("Choose a folder", "",7)
  79. If $OutFold <> "" Then
  80. GUICtrlSetData($OutputFolder, $OutFold)
  81. EndIf
  82. Case $nMsg= $GO
  83. $InPath=GUICtrlRead ($InputFolder)
  84. $OutPath= GUICtrlRead($OutputFolder)
  85. $InEncoder = GUICtrlRead ($InputEncoder)
  86. $OutEncoder = GUICtrlRead ($OutputEncoder)
  87. If StringInStr($InPath,"\") = 0 Then
  88. MsgBox (16, "Caution!","Please select a folder!")
  89. ElseIf $InEncoder = $OutEncoder And $OutEncoder <> "JPG" Or $InEncoder = "" Then
  90. MsgBox (16, "Caution!","Please choose different encoder/decoder")
  91. Else
  92. ; do the conversion process...
  93. ; do the progress bar GUI
  94. $Form1 = GUICreate("", 420, 100,-1, -1,BitOR($WS_POPUP,$WS_BORDER),$WS_EX_TOOLWINDOW)
  95. $ProgFile = GUICtrlCreateProgress(10, 10, 400, 15, $PBS_SMOOTH)
  96. $ProgAll = GUICtrlCreateProgress(10, 60, 400, 15, $PBS_SMOOTH)
  97. $Label1 = GUICtrlCreateLabel("", 10, 80, 400, 17)
  98. $Label2 = GUICtrlCreateLabel("", 10, 30, 400, 17)
  99. GUISetState(@SW_SHOW)
  100. ;
  101. If $OutEncoder ="JPG" Then ; Set JPG quality
  102. $TParam = _GDIPlus_ParamInit(1)
  103. $Datas = DllStructCreate("int Quality")
  104. DllStructSetData($Datas, "Quality", $JPGQuality)
  105. _GDIPlus_ParamAdd($TParam, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($Datas))
  106. $Param = DllStructGetPtr($TParam)
  107. EndIf
  108. If IsDllStruct($Param) Then $Param = DllStructGetPtr($TParam)
  109. ;process itself
  110. $FileList=_FileListToArray($InPath, "*."& $InEncoder, 1)
  111. If @error <> 0 Then
  112. MsgBox(16, "Caution!","No files found or invalid path!")
  113. Else
  114. _GDIPlus_Startup()
  115. For $i = 1 To $FileList[0]
  116. GUICtrlSetData($ProgAll, ($i/$FileList[0])*100)
  117. GUICtrlSetData($Label2, $InPath&"\"&$FileList[$i])
  118. GUICtrlSetData($Label1, $i&" / "&$FileList[0])
  119. $image = _GDIPlus_ImageLoadFromFile($InPath&"\"&$FileList[$i])
  120. $clsid = _GDIPlus_EncodersGetCLSID($OutEncoder)
  121. GUICtrlSetData($ProgFile, 25)
  122. _GDIPlus_ImageSaveToFileEx($image, StringReplace($OutPath&"\"&$FileList[$i],"."&$InEncoder,"."&$OutEncoder), $clsid,$Param)
  123. GUICtrlSetData($ProgFile, 75)
  124. FileSetTime ( StringReplace($OutPath&"\"&$FileList[$i],"."&$InEncoder,"."&$OutEncoder), FileGetTime ( $InPath&"\"&$FileList[$i], 0,1), 0 )
  125. FileSetTime ( StringReplace($OutPath&"\"&$FileList[$i],"."&$InEncoder,"."&$OutEncoder), FileGetTime ( $InPath&"\"&$FileList[$i], 1,1), 1 )
  126. GUICtrlSetData($ProgFile, 100)
  127. Next
  128. _GDIPlus_Shutdown()
  129. MsgBox(64, "Done!","Done!")
  130. EndIf
  131. GUISetState(@SW_HIDE,$Form1)
  132. EndIf
  133. Case $OutEncoder <> $OldOutEncoder
  134. If $OutEncoder <> "JPG" Then
  135. GUICtrlSetState ($Group3,$GUI_DISABLE)
  136. GUICtrlSetState ($Slider,$GUI_DISABLE)
  137. GUICtrlSetState ($JPGQlty,$GUI_DISABLE)
  138. Else
  139. GUICtrlSetState ($Group3,$GUI_ENABLE)
  140. GUICtrlSetState ($Slider,$GUI_ENABLE)
  141. GUICtrlSetState ($JPGQlty,$GUI_ENABLE)
  142. EndIf
  143. $OldOutEncoder = $OutEncoder
  144. Case $ValSlider <> $OldValSlider
  145. GUICtrlSetData($JPGQlty,100-$ValSlider)
  146. $OldValSlider = $ValSlider
  147. Case $JPGQuality <> $OldJPGQuality
  148. GUICtrlSetData($Slider, 100-$JPGQuality)
  149. If $JPGQuality > 100 Then $JPGQuality = 100
  150. If $JPGQuality < 0 Then $JPGQuality = 0
  151. GUICtrlSetData($JPGQlty,$JPGQuality)
  152. $OldJPGQuality = $JPGQuality
  153. EndSelect
  154. WEnd

comments powered by Disqus