;~ #RequireAdmin ;thought this would be needed for moving files, maybe, but nah, it's not #NoTrayIcon #include #include #include #include <_FileListToArrayEx.au3> #include $inputFolder = FileSelectFolder("Open Input Folder", "\input"); ;Create the GUI $hGui = GUICreate("Quick Photo Sorter", 1200, 910) GUISetBkColor($COLOR_GRAY) $butOk = GUICtrlCreateButton("Favourite", 5, 875, 327, 30) $butPrev = GUICtrlCreateButton("<<", 337, 875, 163, 30) $butRel = GUICtrlCreateButton("Reload", 505, 875, 192, 30) ;reload button needed, because image is not being refreshed by itself $butNext = GUICtrlCreateButton(">>", 702, 875, 163, 30) $butNah = GUICtrlCreateButton("Sort out", 868, 875, 327, 30) $imgField_size_x = 1180 $imgField_size_y = 850 Local $labelNo, $pic, $height, $width, $ratio GUISetState(@SW_SHOW, $hGui) $arr = _FileListToArrayEx($inputFolder, '*.jpg;*.jpeg;*.png;*.gif;*.bmp', 1) ;TODO: figure out how to exclude subfolders While UBound($arr) = 0 ;check if selected folder contains photo files, if not, let the user retry (or abort) $getmsg = MsgBox(1, "No Photos", "The folder you have selected contains no image files.") Switch $getmsg Case 1 $inputFolder = FileSelectFolder("Open Input Folder", "\input"); $arr = _FileListToArrayEx($inputFolder, '*.jpg;*.jpeg;*.png;*.gif;*.bmp',1) Case 2 Exit EndSwitch WEnd ;~ _ArrayDisplay($arr, "$aFileList") ;debugging purpose $iterator = 1 _GDIPlus_Startup() $graphics = _GDIPlus_GraphicsCreateFromHWND($hgui) displayImage() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $butOk keep() nextImage() Case $butNah sort_out() nextImage() Case $butNext nextImage() Case $butPrev prevImage() Case $butRel _GDIPlus_ImageDispose($pic) displayImage() EndSwitch WEnd Func nextImage() ;shows the next image without removing the current one from the array GUICtrlDelete($labelNo) GUISetBkColor($COLOR_GRAY) _GDIPlus_ImageDispose($pic) increaseIterator() displayImage() EndFunc Func prevImage();shows the previous image without removing the current one from the array GUICtrlDelete($labelNo) GUISetBkColor($COLOR_GRAY) _GDIPlus_ImageDispose($pic) decreaseIterator() displayImage() EndFunc Func getFileName() $Str = StringSplit($arr[$iterator], "\") return $Str[UBound($Str)-1] EndFunc Func keep() ;copies the picture to keep into the subfolder "_keep" (wanted: move the picture, but does not work) ;~ FileMove($arr[$iterator], "\_Favourites\" & getFileName(), 9) ;Why doesn't this work? FileCopy($arr[$iterator], $inputFolder & "\_Favourites\", $FC_OVERWRITE + $FC_CREATEPATH) removeImageFromArray() EndFunc Func sort_out() ;simply skips the current picture, but removes it from the array (wanted: move the picture to a folder called "unwanted" or sth like this, but does not work) removeImageFromArray() EndFunc Func removeImageFromArray() ;removes the image from the array and adjusts the iterator If NOT (checkArrayEnd()) Then _ArrayDelete($arr, $iterator) $iterator = $iterator - 1 Else MsgBox(1,"Work is done","You have finished sorting your collection, so there is nothing more to display.") EndIf EndFunc Func displayImage() ;display the image fittingly into the gui ;read height and width and calculate the ascpet ratio ;~ $pic = _GDIPlus_ImageLoadFromFile($inputFolder & $arr[$iterator]) ;use this with standard FileListToArrayFunction $pic = _GDIPlus_ImageLoadFromFile($arr[$iterator]) $height = _GDIPlus_ImageGetHeight($pic) $width = _GDIPlus_ImageGetWidth($pic) $ratio = $width/$height ;~ $labelx = GUICtrlCreateLabel("X: " & $width, 0, 0) ;~ $labely = GUICtrlCreateLabel("Y: " & $height, 50, 0) ;~ $labelRatio = GUICtrlCreateLabel("R: " & $ratio, 100, 0) $labelNo = GUICtrlCreateLabel("File: " & $iterator & "/" & (Ubound($arr)-1) & " File name: " & $arr[$iterator], 0, 0) ;resize if $width > $height Then $width = $imgField_size_x $height = $width/$ratio ElseIf $height > $width OR $height = $width Then $height = $imgField_size_y $width = $height*$ratio EndIf ;after resize check if the boundaries are exeeded and resize again if $width > $imgField_size_x Then $width = $imgField_size_x $height = $width/$ratio ElseIf $height > $imgField_size_y Then $height = $imgField_size_y $width = $height*$ratio EndIf $pic = _GDIPlus_ImageResize ($pic, $width, $height) ;now calculate the center position $posX = 10 + ($imgField_size_x/2) - ($width/2) $posY = 20 + ($imgField_size_y/2) - ($height/2) ;display the picture _GDIPlus_GraphicsDrawImage($graphics, $pic, $posX, $posY) EndFunc Func increaseIterator() ;for displaying the next picture if NOT (checkArrayEnd()) Then If $iterator < Ubound($arr) - 1 Then $iterator = $iterator + 1 Else $iterator = 1 EndIf EndIf EndFunc Func decreaseIterator() ;for displaying the previous picture if NOT (checkArrayEnd()) Then If $iterator > 1 Then $iterator = $iterator - 1 Else $iterator = Ubound($arr) - 1 EndIf EndIf EndFunc Func checkArrayEnd() ;preventing crashes, because the array gets empty after skipping all pictures If (UBound($arr)-1) = 0 Then Return true Else Return False EndIf EndFunc