Popular Post TheSaint Posted March 16 Popular Post Share Posted March 16 (edited) BIG THANKS to @UEZ for his code, which I adapted, plus adding some of my own. See his post here. I spent quite a while trying to come up with something simple to include in a program of mine. The examples in the Help file didn't quite do it for me, some very complex. Here's an image I needed to rotate by 1 degree right, and then trim and resize, for embedding into my FLAC and MP3 files for that album. The image was sourced from eBay, as alas Discogs let me down. Admittedly the album title wasn't very helpful, and there are two other volumes, though I only have the first one. Anyway, I have provided the image, so you can test and play around with it. expandcollapse popup#include <GDIPlus.au3> ; BIG THANKS to UEZ ; I modified his example from - https://www.autoitscript.com/forum/topic/155932-gdiplus-need-help-with-rotating-an-image/?do=findComment&comment=1127106 Global $hBackbuffer, $hBitmap, $hBitmap_Scaled, $hClone, $hCoverBitmap, $hCoverGC, $hCoverMatrix, $hCoverTexture, $hGraphic, $iH, $inifile, $iW, $newfile, $sCLSID $inifile = @ScriptDir & "\Settings.ini" $newfile = @ScriptDir & "\rotated.jpg" If FileExists($newfile) Then FileDelete($newfile) _GDIPlus_Startup() $hCoverTexture = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\cover.jpg") $iW = _GDIPlus_ImageGetWidth($hCoverTexture) $iH = _GDIPlus_ImageGetHeight($hCoverTexture) $iW = $iW / 2 $iH = $iH / 2 $hBitmap_Scaled = _GDIPlus_ImageResize($hCoverTexture, $iW, $iH, 5) Global $hGUI = GUICreate("", $iW, $iH) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphic) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) $hCoverBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hBackbuffer) $hCoverGC = _GDIPlus_ImageGetGraphicsContext($hCoverBitmap) $hCoverMatrix = _GDIPlus_MatrixCreate() Rotate() Sleep(1000) Local $crop = 1, $resize = 1, $trim If $crop = 1 Then Local $lft = IniRead($inifile, "Image Crop", "left", 0) Local $tp = IniRead($inifile, "Image Crop", "top", 0) Local $wd = IniRead($inifile, "Image Crop", "width", $iW) Local $ht = IniRead($inifile, "Image Crop", "height", $iH) Local $size = $lft & "_" & $tp & "_" & $wd & "_" & $ht ; $trim = InputBox("Crop Query", "Please set the desired values." & @LF & @LF & "Left_Top_Width_Height", $size, "", 200, 160, Default, Default) If @error = 0 Then $trim = StringSplit($trim, "_", 1) If $trim[0] = 4 Then $lft = $trim[1] $tp = $trim[2] $wd = $trim[3] $ht = $trim[4] IniWrite($inifile, "Image Crop", "left", $lft) IniWrite($inifile, "Image Crop", "top", $tp) IniWrite($inifile, "Image Crop", "width", $wd) IniWrite($inifile, "Image Crop", "height", $ht) If $wd < 1 Then $wd = $iW EndIf If $ht < 1 Then $ht = $iH EndIf If $lft < 1 Then $lft = 0 EndIf If $tp < 1 Then $tp = 0 EndIf $wd = $wd - $lft $ht = $ht - $tp ; 188_55_630_496 $hClone = _GDIPlus_BitmapCloneArea($hBitmap, $lft, $tp, $wd, $ht, $GDIP_PXF24RGB) Else MsgBox(262192, "Crop Error", "Wrong number of values specified. 4 required.", 0, $DropboxGUI) EndIf EndIf Else $hClone = "none" EndIf If $resize = 1 Then If $hClone = "none" Then $hClone_Scaled = _GDIPlus_ImageResize($hBitmap, 600, 600, 5) Else $hClone_Scaled = _GDIPlus_ImageResize($hClone, 600, 600, 5) EndIf Else $hClone_Scaled = $hBitmap EndIf $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") _GDIPlus_ImageSaveToFileEx($hClone_Scaled, $newfile, $sCLSID) If FileExists($newfile) Then ShellExecute($newfile) GUIDelete($hGUI) _GDIPlus_BitmapDispose($hBitmap_Scaled) _GDIPlus_BitmapDispose($hClone_Scaled) If $hClone <> "none" Then _GDIPlus_ImageDispose($hClone) _GDIPlus_MatrixDispose($hCoverMatrix) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hCoverGC) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_BitmapDispose($hCoverBitmap) _GDIPlus_BitmapDispose($hCoverTexture) _GDIPlus_ImageDispose($hBackbuffer) _GDIPlus_Shutdown() Exit Func Rotate() _GDIPlus_GraphicsClear($hBackbuffer, 0xFF6495ED) _GDIPlus_MatrixTranslate($hCoverMatrix, 0, 0) ; move it back to 0, 0 since (112 / 2) and (37 / 2) are it's middle origin point _GDIPlus_MatrixRotate($hCoverMatrix, 1) ; rotate it around it's middle origin point (minus to rotate left) _GDIPlus_GraphicsSetTransform($hCoverGC, $hCoverMatrix) _GDIPlus_MatrixTranslate($hCoverMatrix, 0, 0) _GDIPlus_GraphicsClear($hCoverGC, 0xFFFFFFFF) ; show the GC _GDIPlus_GraphicsDrawImageRect($hCoverGC, $hCoverTexture, 0, 0, $iW, $iH) ; place the arrow at the center of it's GC _GDIPlus_GraphicsDrawImage($hBackbuffer, $hCoverBitmap, 0, 0) ; move it's GC by an offset so the image is at the correct XY using it's origin _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH) EndFunc Resulting image. Enjoy! P.S. I should have probably removed the comments by UEZ in the Rotate function, especially as I changed it to not rotate around the center. Some of the code in that function is likely redundant too, because of that change. Edited March 16 by TheSaint TheDcoder, argumentum, Xandy and 3 others 6 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Popular Post UEZ Posted March 16 Popular Post Share Posted March 16 (edited) Hi @TheSaint Here a fast hack how to rotate the image by drawing a line on the edge of the CD cover to give you more flexibility. expandcollapse popup;Coded by UEZ 2024-03-16 #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $sFile = "cover.jpg" ;FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.gif;*.bmp)") If @error Then Exit Const $fPI = ACos(-1) _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile($sFile), $hImage_rotated Global $aDim = _GDIPlus_ImageGetDimension($hImage) Global Const $hGUI = GUICreate("Image Rotate", $aDim[0], $aDim[1]) Global Const $hDC = _WinAPI_GetDC($hGUI) Global Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aDim[0], $aDim[1]) Global Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Global Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) Global Const $hPen = _GDIPlus_PenCreate(0xFFFFFFFF) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4) _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) GUISetCursor(3, 0, $hGUI) GUISetState() Global $aCI, $c = 0, $x1, $y1, $x2, $y2 Do _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) $aCI = GUIGetCursorInfo($hGUI) If $aCI[2] Then While GUIGetCursorInfo($hGUI)[2] Sleep(1) WEnd $c += 1 Switch $c Case 1 $x1 = $aCI[0] $y1 = $aCI[1] Case 2 $x2 = $aCI[0] $y2 = $aCI[1] EndSwitch EndIf Switch $c Case 1 _GDIPlus_GraphicsDrawLine($hCanvas, $x1, $y1, $aCI[0], $aCI[1], $hPen) Case 2 _GDIPlus_GraphicsDrawLine($hCanvas, $x1, $y1, $x2, $y2, $hPen) EndSwitch _WinAPI_BitBlt($hDC, 0, 0, $aDim[0], $aDim[1], $hDC_backbuffer, 0, 0, $SRCCOPY) If $aCI[3] Then ExitLoop Sleep(10) Until False _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) _GDIPlus_ImageRotate($hImage, 360 - CalculateAngle($x1, $y1, $x2, $y2)) $hImage_rotated = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) ;save result _GDIPlus_GraphicsClear($hCanvas) Do _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage_rotated, 0, 0, $aDim[0], $aDim[1]) _WinAPI_BitBlt($hDC, 0, 0, $aDim[0], $aDim[1], $hDC_backbuffer, 0, 0, $SRCCOPY) Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_ReleaseDC($hGUI, $hDC) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _GDIPlus_PenDispose($hPen) _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hImage_rotated) _GDIPlus_Shutdown() Func CalculateAngle($x1, $y1, $x2, $y2) Return ATan(($y2 - $y1) / ($x2 - $x1)) * (180 / $fPi) + ($x1 > $x2 ? 180 : ($y1 > $y2 ? 360 : 0)) EndFunc Func _GDIPlus_ImageRotate($hImage, $fDegree) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fDegree = ' & $fDegree & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixTranslate($hMatrix, $aDim[0] / 2, $aDim[1] / 2) _GDIPlus_MatrixRotate($hMatrix, $fDegree) _GDIPlus_MatrixTranslate($hMatrix, -$aDim[0] / 2, -$aDim[1] / 2) _GDIPlus_GraphicsSetTransform($hCanvas, $hMatrix) _GDIPlus_MatrixDispose($hMatrix) EndFunc After you have started the script and the image is displayed click (lmb) on the left upper corner of the CD cover move the move the mouse to the right upper corner of the CD cover and press click the lmb again press the right mouse button The image should be rotated according to the angle of x1, y1 and x2, y2. You may add a crop function to get only a desired area of the image. 😉 Edited March 16 by UEZ Gianni, TheDcoder, argumentum and 4 others 5 2 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
TheSaint Posted March 16 Author Share Posted March 16 1 hour ago, UEZ said: Here a fast hack how to rotate the image by drawing a line on the edge of the CD cover. Thanks for that @UEZ, you are the GDI+ Master, and I shall indeed check it out and look into the crop side of it too. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Gianni Posted March 17 Share Posted March 17 @UEZ, nice. I've fiddled with the UEZ listing a bit you can now rotate the image visually with a slider you can also finely adjust the rotation with two buttons I also added 2 "rulers", one vertical and one horizontal, which you can move by clicking on them and dragging them, in order to have a reference to control the orientation of the image expandcollapse popup;Coded by UEZ 2024-03-16 ; [few mods by Gianni :) ] #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ; --- rulers ----- Global $iThickness = 4 Global $hGUI1 = GUICreate("", @DesktopWidth, $iThickness, 0, @DesktopHeight / 2, $WS_POPUP, $WS_EX_TOPMOST) GUICtrlCreateLabel("", 0, 0, @DesktopWidth, $iThickness, -1, $GUI_WS_EX_PARENTDRAG) GUISetBkColor(0x00ff00, $hGUI1) WinSetTrans($hGUI1, "", 127) GUISetState(@SW_SHOW, $hGUI1) Global $hGUI2 = GUICreate("", $iThickness, @DesktopHeight, @DesktopWidth / 2, 0, $WS_POPUP, $WS_EX_TOPMOST) GUICtrlCreateLabel("", 0, 0, $iThickness, @DesktopHeight, -1, $GUI_WS_EX_PARENTDRAG) GUISetBkColor(0x00ff00, $hGUI2) WinSetTrans($hGUI2, "", 127) GUISetState(@SW_SHOW, $hGUI2) ; ---------------- Global $sFile = "cover.jpg" ;FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.gif;*.bmp)") If @error Then Exit Const $fPI = ACos(-1) _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile($sFile) Global $aDim = _GDIPlus_ImageGetDimension($hImage) Global Const $hGUI = GUICreate("Image Rotate", $aDim[0], $aDim[1] + 50) Global Const $hDC = _WinAPI_GetDC($hGUI) Global Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aDim[0], $aDim[1]) Global Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Global Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) Global Const $hPen = _GDIPlus_PenCreate(0xFFFFFFFF) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4) _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) Global $hButton1 = GUICtrlCreateButton(' < ', 10, $aDim[1] + 10, 40) Global $Slider = GUICtrlCreateSlider(60, $aDim[1] + 10, 360, 25) GUICtrlSetLimit(-1, 360, 0) ; change min/max value Global $hButton2 = GUICtrlCreateButton(' > ', 430, $aDim[1] + 10, 40) Global $hSlider = GUICtrlGetHandle($Slider) Global $Dummy = GUICtrlCreateDummy() GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL") ;horz slider GUISetState(@SW_SHOW, $hGUI) _ImageRefresh() ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Dummy _GDIPlus_ImageRotate($hImage, GUICtrlRead($Slider)) _ImageRefresh() Case $hButton1 _FineTuning(1) Case $hButton2 _FineTuning(2) EndSwitch WEnd _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_ReleaseDC($hGUI, $hDC) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _GDIPlus_PenDispose($hPen) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Func _FineTuning($iDirection) Local Static $iAngle Local Static $iSliderPos = GUICtrlRead($Slider) If $iSliderPos <> GUICtrlRead($Slider) Then $iAngle = 0 $iSliderPos = GUICtrlRead($Slider) EndIf Switch $iDirection Case 1 $iAngle -= .1 If $iAngle < 0 Then $iAngle = .9 $iSliderPos -= 1 If $iSliderPos < 0 Then $iSliderPos = 359 GUICtrlSetData($Slider, $iSliderPos) EndIf Case 2 $iAngle += .1 If $iAngle > .9 Then $iAngle = 0 $iSliderPos += 1 If $iSliderPos > 359 Then $iSliderPos = 0 GUICtrlSetData($Slider, $iSliderPos) EndIf EndSwitch _GDIPlus_ImageRotate($hImage, $iSliderPos + $iAngle) _ImageRefresh() EndFunc ;==>_FineTuning Func _ImageRefresh() _GDIPlus_GraphicsClear($hCanvas) _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) _WinAPI_BitBlt($hDC, 0, 0, $aDim[0], $aDim[1], $hDC_backbuffer, 0, 0, $SRCCOPY) EndFunc ;==>_ImageRefresh Func _GDIPlus_ImageRotate($hImage, $fDegree) ; ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fDegree = ' & $fDegree & @TAB & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixTranslate($hMatrix, $aDim[0] / 2, $aDim[1] / 2) _GDIPlus_MatrixRotate($hMatrix, $fDegree) _GDIPlus_MatrixTranslate($hMatrix, -$aDim[0] / 2, -$aDim[1] / 2) _GDIPlus_GraphicsSetTransform($hCanvas, $hMatrix) _GDIPlus_MatrixDispose($hMatrix) EndFunc ;==>_GDIPlus_ImageRotate Func WM_HVSCROLL($hwnd, $iMsg, $wParam, $lParam) #forceref $hwnd, $iMsg, $wParam, $lParam Switch $iMsg Case $WM_HSCROLL Switch $lParam Case $hSlider GUICtrlSendToDummy($Dummy, GUICtrlRead($Slider)) EndSwitch Case $WM_VSCROLL EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_HVSCROLL SOLVE-SMART, Musashi, TheSaint and 1 other 2 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
UEZ Posted March 17 Share Posted March 17 @Gianni There are certainly many ways to design TheSaint's app. 😉 TheSaint 1 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Gianni Posted March 17 Share Posted March 17 4 hours ago, UEZ said: @Gianni There are certainly many ways to design TheSaint's app. 😉 more ideas, more fun... 🙂 added a crop and copy to clipboard function (UDF download required. see link in list) I hope there are no bugs expandcollapse popup;Coded by UEZ 2024-03-16 ; [few mods by Gianni :) ] #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Clipboard.au3> #include <ScreenCapture.au3> #include <.\CropTool.au3> ; <-- get this from below link ; https://www.autoitscript.com/forum/topic/203545-%E2%9C%82%EF%B8%8F-quick-crop-tool/ Opt("GUICloseOnESC", 0) ; --- rulers ----- Global $iThickness = 5 Global $hGUI1 = GUICreate("", @DesktopWidth, $iThickness, 0, @DesktopHeight / 2, $WS_POPUP, $WS_EX_TOPMOST) GUICtrlCreateLabel("", 0, 0, @DesktopWidth, $iThickness, -1, $GUI_WS_EX_PARENTDRAG) GUISetBkColor(0x00ff00, $hGUI1) WinSetTrans($hGUI1, "", 127) GUISetState(@SW_HIDE, $hGUI1) Global $hGUI2 = GUICreate("", $iThickness, @DesktopHeight, @DesktopWidth / 2, 0, $WS_POPUP, $WS_EX_TOPMOST) GUICtrlCreateLabel("", 0, 0, $iThickness, @DesktopHeight, -1, $GUI_WS_EX_PARENTDRAG) GUISetBkColor(0x00ff00, $hGUI2) WinSetTrans($hGUI2, "", 127) GUISetState(@SW_HIDE, $hGUI2) ; ---------------- Global $sFile = "cover.jpg" ; FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.gif;*.bmp)") If @error Then Exit Global $aRect, $bResult, $hBmp, $aTemp, $bPreviousStatus, $aBKcolor[2] = [0x008800, 0x00ff00] _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile($sFile) Global $aDim = _GDIPlus_ImageGetDimension($hImage) Global Const $hGUI = GUICreate("Image Rotate", $aDim[0], $aDim[1] + 50) Global Const $hDC = _WinAPI_GetDC($hGUI) Global Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aDim[0], $aDim[1]) Global Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Global Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) Global Const $hPen = _GDIPlus_PenCreate(0xFFFFFFFF) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4) _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) Global $hButton1 = GUICtrlCreateButton(' < ', 10, $aDim[1] + 10, 40) GUICtrlSetTip(-1, 'fine rotation to the left') Global $Slider = GUICtrlCreateSlider(60, $aDim[1] + 10, 360, 25) GUICtrlSetLimit(-1, 360, 0) ; change min/max value GUICtrlSetTip(-1, 'slide to rotate the image') Global $hButton2 = GUICtrlCreateButton(' > ', 430, $aDim[1] + 10, 40) GUICtrlSetTip(-1, 'fine rotation to the right') Global $hCrop = GUICtrlCreateButton(' # ', 480, $aDim[1] + 10, 40) GUICtrlSetTip(-1, '1) move & resize the tool' & @CR & '2) right-click inside the tool area to copy the image' & @CR & '3) hit ESC to cancel cropping', 'Crop Tool') Global $hButton3 = GUICtrlCreateButton(' + ', 530, $aDim[1] + 10, 40) GUICtrlSetBkColor(-1, $aBKcolor[_SwitcRuler()]) GUICtrlSetTip(-1, 'show/hide ruler') Global $hSlider = GUICtrlGetHandle($Slider) Global $Dummy = GUICtrlCreateDummy() GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL") ;horz slider GUISetState(@SW_SHOW, $hGUI) _ImageRefresh() ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Dummy _GDIPlus_ImageRotate($hImage, GUICtrlRead($Slider)) _ImageRefresh() Case $hButton1 _FineTuning(1) Case $hButton2 _FineTuning(2) Case $hCrop $bPreviousStatus = _SwitcRuler(0) $aTemp = WinGetPos($hGUI) $aRect = _Crop($aTemp[0] + ($aTemp[2] / 2) - 50, $aTemp[1] + ($aTemp[3] / 2) - 50) If Not @extended Then ; below snippet by UEZ ; https://www.autoitscript.com/forum/topic/129333-screen-capture-to-clipboard/?do=findComment&comment=898287 $hBmp = _ScreenCapture_Capture('', $aRect[0], $aRect[1], $aRect[0] + $aRect[2] - 1, $aRect[1] + $aRect[3] - 1, False) $bResult = _ClipBoard_Open(0) + _ClipBoard_Empty() + Not _ClipBoard_SetDataEx($hBmp, $CF_BITMAP) _ClipBoard_Close() If $bResult = 2 Then MsgBox($MB_ICONINFORMATION, '', "the area was copied to the clipboard", 2) Else MsgBox($MB_ICONERROR, '', "Something went wrong", 2) EndIf Else EndIf _SwitcRuler($bPreviousStatus) Case $hButton3 _SwitcRuler(Not _SwitcRuler()) GUICtrlSetBkColor($hButton3, $aBKcolor[_SwitcRuler()]) EndSwitch WEnd _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_ReleaseDC($hGUI, $hDC) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _GDIPlus_PenDispose($hPen) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Func _FineTuning($iDirection) Local Static $iAngle Local Static $iSliderPos = GUICtrlRead($Slider) If $iSliderPos <> GUICtrlRead($Slider) Then $iAngle = 0 $iSliderPos = GUICtrlRead($Slider) EndIf Switch $iDirection Case 1 $iAngle -= .1 If $iAngle < 0 Then $iAngle = .9 $iSliderPos -= 1 If $iSliderPos < 0 Then $iSliderPos = 359 GUICtrlSetData($Slider, $iSliderPos) EndIf Case 2 $iAngle += .1 If $iAngle > .9 Then $iAngle = 0 $iSliderPos += 1 If $iSliderPos > 359 Then $iSliderPos = 0 GUICtrlSetData($Slider, $iSliderPos) EndIf EndSwitch _GDIPlus_ImageRotate($hImage, $iSliderPos + $iAngle) _ImageRefresh() EndFunc ;==>_FineTuning Func _ImageRefresh() _GDIPlus_GraphicsClear($hCanvas) _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) _WinAPI_BitBlt($hDC, 0, 0, $aDim[0], $aDim[1], $hDC_backbuffer, 0, 0, $SRCCOPY) EndFunc ;==>_ImageRefresh Func _SwitcRuler($bOn = 2) Local Static $bStatus = 0 Local $bReturn = $bStatus If $bOn = 1 Then GUISetState(@SW_SHOW, $hGUI1) GUISetState(@SW_SHOW, $hGUI2) $bStatus = 1 ElseIf $bOn = 0 Then GUISetState(@SW_HIDE, $hGUI1) GUISetState(@SW_HIDE, $hGUI2) $bStatus = 0 EndIf ; Else Return $bReturn EndFunc ;==>_SwitcRuler Func _GDIPlus_ImageRotate($hImage, $fDegree) ; ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fDegree = ' & $fDegree & @TAB & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixTranslate($hMatrix, $aDim[0] / 2, $aDim[1] / 2) _GDIPlus_MatrixRotate($hMatrix, $fDegree) _GDIPlus_MatrixTranslate($hMatrix, -$aDim[0] / 2, -$aDim[1] / 2) _GDIPlus_GraphicsSetTransform($hCanvas, $hMatrix) _GDIPlus_MatrixDispose($hMatrix) EndFunc ;==>_GDIPlus_ImageRotate Func WM_HVSCROLL($hwnd, $iMsg, $wParam, $lParam) #forceref $hwnd, $iMsg, $wParam, $lParam Switch $iMsg Case $WM_HSCROLL Switch $lParam Case $hSlider GUICtrlSendToDummy($Dummy, GUICtrlRead($Slider)) EndSwitch Case $WM_VSCROLL EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_HVSCROLL TheSaint and UEZ 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
UEZ Posted March 18 Share Posted March 18 few mods by Gianni slightly understated 😉 Now we have hijacked TheSaint's topic... 👉👈 TheSaint and Gianni 2 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Gianni Posted March 18 Share Posted March 18 (edited) ...it would be useful to modify the main window so that, instead of adapting to the size of the loaded image, it should allow you to load the image in a fixed-size (and/or resizable) window, allowing you to scroll the image within it. ... Edited March 19 by Gianni reduced post length Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
TheSaint Posted March 19 Author Share Posted March 19 Nice to know I have inspired you two masterminds. I am looking forward to checking these out. BIG THANKS. On 3/18/2024 at 7:37 PM, Gianni said: ...it would be useful to modify the main window so that, instead of adapting to the size of the loaded image, it should allow you to load the image in a fixed-size (and/or resizable) window, allowing you to scroll the image within it. ... I'm not sure about that, but certainly the major flaw of my code, is that you only see the end result image, so it is somewhat of a painstaking process of trial and error. The only real known is the final required 600x600 pixel size for the CD artwork that I embed in my music files. Admittedly most of the time I can source good enough CD covers from Discogs (primarily). It is only the odd rare instance when I need to crop, and even rarer to rotate. Trial and error guesses though, can waste a lot of time, so once again BIG THANKS. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
KaFu Posted March 19 Share Posted March 19 Fyi and for comparisons, here's the picture rotated with BIC v2. TheSaint 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
TheSaint Posted March 19 Author Share Posted March 19 @KaFu Thanks. Not sure why that did not turn up in my search here the other day ... or maybe it did and I didn't browse far enough. Anyway, I've downloaded it to have a bit of a play when I get the time. Normally, in the past, I have always used the free IrfanView for most of my image needs, often via its command-line, but I mostly try to avoid any kind of dependency these days, if I can. I could have just edited with that, as I have done so many times in the past. One issue for me though, has always been what JPG quality to save at, and GDIPlus simplifies that for me. That is especially the case, where the source file is not very large, and so not much quality to play around with, and so quite possibly I will end up with some even poorer looking image, without there seeming much I can do about that. I mostly care with my CD covers, because they are displayed big on my TV, and any faults can be glaring. KaFu 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
KaFu Posted March 19 Share Posted March 19 (edited) With using GDI to create JPGs to colors are always off. The problem (after reading your edits) is probably due to the fact that GDI+ uses 4:1:1 subsampling for JPG files in it's default Encoder. The issue is that GDI+ enables chroma subsampling which modifies the color values accordingly. That's why I use this program in BIC. I first write any resulting bitmap to a lossless temporary PNG file, and then convert it using "jpge". https://code.google.com/archive/p/jpeg-compressor/ Alternatively you can always convert the output to PNG, where the output files are similarly small as with JPG imho (with the right settings), but lossless and with correct colors. Edited March 19 by KaFu TheSaint 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
TheSaint Posted March 20 Author Share Posted March 20 13 hours ago, KaFu said: Alternatively you can always convert the output to PNG, where the output files are similarly small as with JPG imho (with the right settings), but lossless and with correct colors. When not doing CD covers I tend to use PNG, but my recollection is that the embedded artwork in an MP3 or FLAC file needs to be JPG. I also use JPG for the folder image, as in Folder.jpg. which is what Windows or devices use. I can't say I have noticed that color issue when I use GDI+. The problem for me with an otherwise great program like IrfanView, is the quality when saving. If I go for 100%, I often end up with a file size multiple times bigger than the original, which I don't want and concerns me. So in the past I have had to play around with the degree of quality to get a better all-round result. The concern for me though, is a whether it is a bit like the old MP3 editors, that would convert to WAV so you could edit, and then reconvert back to MP3, having reduced the quality of the MP3 even more in the process. With GDI+ I get a decent size file without any obvious or major difference in size or look, reduction or enlargement amounts aside. I have it set to the value recommended, which is 7 I think. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
KaFu Posted March 20 Share Posted March 20 (edited) In your code you do not set the Quality for the output. Setting it manually I stumbled over an odd behavior. What baffles me is the huge difference in JPG size, depending on the input file, and the behavior of the encoder. When the input file is either BMP or PNG, the JPG encoder seems to default to a Quality of 75 When the input file is JPG, the JPG encoder does not seem to perform a re-encoding, but uses exactly the same Quality as the input file (I assume, as it's the same file size in KB) Input BMP = 6076 Output JPG default = 216 Output JPG 75 = 216 Input PNG = 221 Output JPG default = 216 Output JPG 75 = 216 Input JPG = 734 Output JPG default = 734 Output JPG 75 = 208 You might save some KBs when you set the encoder Quality explicitly in your code, depends on the input quality. I always default to 95, but 92 is still very good (I think default for IrfanView). expandcollapse popup#include <GDIPlus.au3> #include <ScreenCapture.au3> _GDIPlus_Startup() _Screenshot("bmp") _Screenshot("png") _Screenshot("jpg") Func _Screenshot($sExtension) _ScreenCapture_Capture(@ScriptDir & "\GDIPlus_Image_" & $sExtension & "." & $sExtension) Local $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\GDIPlus_Image_" & $sExtension & "." & $sExtension) ; JPG, no quality param set Local $tParams Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") _GDIPlus_ImageSaveToFileEx($hImage, @ScriptDir & "\GDIPlus_Image_" & $sExtension & "_00_Default.jpg", $sCLSID, $tParams) ; JPG, set to 75 Local $tParams = _GDIPlus_ParamInit(1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", 75) Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local $pParams = DllStructGetPtr($tParams) _GDIPlus_ImageSaveToFileEx($hImage, @ScriptDir & "\GDIPlus_Image_" & $sExtension & "_75.jpg", $sCLSID, $pParams) ; JPG, set to 92 Local $tParams = _GDIPlus_ParamInit(1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", 92) Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local $pParams = DllStructGetPtr($tParams) _GDIPlus_ImageSaveToFileEx($hImage, @ScriptDir & "\GDIPlus_Image_" & $sExtension & "_92.jpg", $sCLSID, $pParams) ; JPG, set to 95 Local $tParams = _GDIPlus_ParamInit(1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", 95) Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local $pParams = DllStructGetPtr($tParams) _GDIPlus_ImageSaveToFileEx($hImage, @ScriptDir & "\GDIPlus_Image_" & $sExtension & "_95.jpg", $sCLSID, $pParams) ; JPG, set to 100 Local $tParams = _GDIPlus_ParamInit(1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", 100) Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local $pParams = DllStructGetPtr($tParams) _GDIPlus_ImageSaveToFileEx($hImage, @ScriptDir & "\GDIPlus_Image_" & $sExtension & "_100.jpg", $sCLSID, $pParams) EndFunc ;==>_Screenshot _GDIPlus_Shutdown() Edit: Regarding the bad quality of the GDI JPG encoder, compare the PNG & BMP screenshot with their JPG pendants. Edited March 21 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
TheSaint Posted June 2 Author Share Posted June 2 (edited) @KaFu My apologies for not replying to you, but I did not get any notification that you had replied. I am here now for a related reason, and will read your post ... and it might assist me with one aspect of my latest issue ... quality. That issue, is in regard to Progressive JPG. I have a need to detect when a JPG is such, using code, plus re-save the JPG as standard rather than Progressive, because my NeoTV 550 hardware media player does not support a Progressive JPG. As you may be aware, I have been steadily going through my CD collection and ripping them to WAV files, and then at some future point converting to both FLAC and MP3, as well as embedding CD cover artwork. A couple of days ago, I discovered that many of my CD images were not displaying on my hardware player. Alas I had temporarily forgotten about the Progressive JPG issue, and now I have a lot of albums to fix ... not only the folder image (Folder.jpg), but also the replacement of that image in my FLAC and MP3 files. So a fair bit of work to do, and of course I want to avoid that in future, so I need a way to quickly and easily detect that a JPG is a Progressive JPG one, and then deal with it with the least amount of quality loss. I am already using a dropbox program I created, to more often than not just rename the folder cover image to just 'Folder.jpg', before then using that image to embed in my FLAC and MP3 files. If it needs to, it also converts to JPG from other formats and even resizes (to either 600x600 pixels or failing that 500x500) and in some cases it also crops. Doing a trial, I discovered that if I pretend to resize, then a Progressive JPG image is converted to a standard one. By pretend, I mean resizing to the existing size. But I noticed that the file size went from 218 Kb to 117 Kb, and that has me concerned, because I don't really want to lose any more quality than I have to, especially as some cover images I have are quite a bit smaller file size wise and not exactly great quality already in some cases. In the distant past, when I found a non working image file that was a Progressive JPG image, I just used IrfanView to re-save as a standard JPG. I was always concerned about the image quality loss though, especially as IrfanView only really gives you options to recompress ... at least as far as I could tell. Anyway, it may be that I am just going to make a bad situation worse, with no choice over the matter, after reading about what a Progressive JPG is. Quote from Wikipedia. Quote There is also an interlaced progressive JPEG format, in which data is compressed in multiple passes of progressively higher detail. This is ideal for large images that will be displayed while downloading over a slow connection, allowing a reasonable preview after receiving only a portion of the data. However, support for progressive JPEGs is not universal. When progressive JPEGs are received by programs that do not support them (such as versions of Internet Explorer before Windows 7) the software displays the image only after it has been completely downloaded. Now to search the forum for some code to detect 'Progressive JPG' in the Exif data. Edited June 2 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
TheSaint Posted June 2 Author Share Posted June 2 (edited) On 3/21/2024 at 4:03 AM, KaFu said: When the input file is either BMP or PNG, the JPG encoder seems to default to a Quality of 75 Yep I have noticed that too. On 3/21/2024 at 4:03 AM, KaFu said: When the input file is JPG, the JPG encoder does not seem to perform a re-encoding, but uses exactly the same Quality as the input file (I assume, as it's the same file size in KB) As you may have noticed in my prior post, I did a pretend resize (dimensions), and the resulting file size was almost half that of the original. On my first attempt, I just loaded the JPG file and then re-saved it, but that did not change the Progressive JPG state, and the file size remained the same. So I tried a resize, resizing from 600x600 to 600x600, so no change at all to dimensions, but significantly reduced in file size, but it did convert to a standard JPG rather than the original Progressive JPG state. On 3/21/2024 at 4:03 AM, KaFu said: In your code you do not set the Quality for the output. That was a deliberate choice, as I was trying to avoid recompressing. Edited June 2 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
TheSaint Posted June 2 Author Share Posted June 2 (edited) Here's a simple little dropbox based script for checking if a JPG file is a Progressive JPG. NOTE - This may be imperfect, because it is counting on a specific byte set to be in the first 200 bytes or not. It has worked for me with a lot of files so far, without a failure. FYI - I did attempt to leverage some help from ChatGPT, and it provided a basic script that did not work. For some weird reason it just looked at the first two bytes of a JPG file, which from my checking is the same for every JPG file. So I kept a few lines of code, while adding many more of my own after some trial and error. An online search provided me with the two bytes I needed (ÿÂ or FFC2). But I found they could also exist later in every file, so I limited the check to the first 200 bytes. I had of course tried to work further with ChatGPT, but ended up faring better on my own. expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: TheSaint Script Function: Check a JPG image file to see if it is a Progressive JPG Template AutoIt script. #ce ---------------------------------------------------------------------------- ; FUNCTIONS ; DropboxGUI() ; IsProgressiveJPG($filepath) #include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> #include <Misc.au3> _Singleton("check-if-progressive-thsaint") Global $filepath DropboxGUI() Exit Func DropboxGUI() Local $Label_drop ; Local $attrib, $Dropbox, $path, $target ; $Dropbox = GuiCreate("Dropbox", 82, 90, Default, Default, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE _ + $WS_CLIPSIBLINGS, $WS_EX_ACCEPTFILES + $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW) ; $Label_drop = GUICtrlCreateLabel("", 0, 0, 80, 88, $SS_CENTER + $SS_NOTIFY) GUICtrlSetState($Label_drop, $GUI_DROPACCEPTED) GUICtrlSetFont($Label_drop, 8, 400) GUICtrlSetTip($Label_drop, "Drop an image file Here!") ; ; SETTINGS $target = "Drop an Image" & @LF & "File HERE" & @LF & "to" & @LF & "See If It Is" & @LF & "Progressive" GUICtrlSetData($Label_drop, @LF & $target) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ;Or $msg = $Item_exit ; Close the Dropbox GUIDelete($Dropbox) ExitLoop Case $msg = $GUI_EVENT_DROPPED ; Image file checked by drag and drop If @GUI_DragId = -1 Then If FileExists(@GUI_DragFile) Then $attrib = FileGetAttrib(@GUI_DragFile) If StringInStr($attrib, "D") < 1 Then $path = @GUI_DragFile If IsProgressiveJPG($path) Then MsgBox(262144, "Progressive JPG", "The file is a Progressive JPG.", 2, $Dropbox) Else MsgBox(262144, "Not Progressive JPG", "The file is NOT a Progressive JPG.", 1, $Dropbox) EndIf Else MsgBox(262192, "Drag Error", "Needs to be a file not folder.", 0, $Dropbox) EndIf Else MsgBox(262192, "Drag Error", "Drag & Drop path doesn't exist.", 0, $Dropbox) EndIf Else MsgBox(262192, "Drag Error", "Drag & Drop failed.", 0, $Dropbox) EndIf Case Else ;;; EndSelect WEnd EndFunc ;=> DropboxGUI Func IsProgressiveJPG($filepath) Local $data, $file ; $file = FileOpen($filepath, $FO_BINARY) If $file = -1 Then Return False EndIf $data = FileRead($file, 200) FileClose($file) ;MsgBox(262144, "Data", $data) ;If StringInStr($data, "ÿÂ") > 0 Then If StringInStr($data, "FFC2") > 0 Then Return True Else Return False EndIf EndFunc P.S. Please reply here if you have a failure or can improve something. Edited June 2 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
TheSaint Posted June 10 Author Share Posted June 10 On 6/3/2024 at 12:05 AM, TheSaint said: So I tried a resize, resizing from 600x600 to 600x600, so no change at all to dimensions, but significantly reduced in file size, but it did convert to a standard JPG rather than the original Progressive JPG state. I have initiated a discussion or query about that image in Chat. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now