DarkKeks Posted May 17, 2016 Share Posted May 17, 2016 Hi iam new here. I used the search but i didn't find a solution for my Problem. I want to resize Some Images in a Folder into a generated Subfolder. The Problem is when the Script is in the selected folder there is no problem, but when i choose another one it gives me @error 4 on the GDIPlus_ImageResize. Hope the german things in my script is no problem for the pro's in this forum. Thanks DarkKeks Spoiler expandcollapse popup#include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> DirChoose() Func DirChoose() Local Const $sMessage = "Wähle den Ordner aus" Global $sFileSelectFolder = FileSelectFolder($sMessage, "") MsgBox (0, "", $sFileselectfolder) If @error Then MsgBox($MB_SYSTEMMODAL, "", "Es wurde Kein Ordner ausgewählt!") Else ImageScan() EndIf EndFunc Func ImageScan() Global $ImageList = _FileListToArray($sFileSelectFolder, "*.jpg",1) MsgBox(0, "" ,$ImageList[0]) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Eingegebener Pfad ist ungültig!") Exit EndIf If @error = 2 Then MsgBox($MB_SYSTEMMODAL, "", "Eingegebener Filter ist ungültig!") Exit EndIf If @error = 3 Then MsgBox($MB_SYSTEMMODAL, "", "Keine Dateien gefunden!") Exit EndIf Resize() EndFunc Func Resize() _GDIPlus_Startup() DirCreate($sFileSelectFolder & "\Thumbs") Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" For $i = 1 to $ImageList[0] $hImg = _GDIPlus_ImageLoadFromFile($ImageList[$i]) $w = _GDIPlus_ImageGetWidth($hImg) $h = _GDIPlus_ImageGetHeight($hImg)/($w/200) _PathSplit($ImageList[$i],$sDrive,$sDir, $sFileName, $sExtension) $hImgre = _GDIPlus_ImageResize($hImg, 200,$h) If @error = 4 Then MsgBox(0, "", "") EndIf _GDIPlus_ImageDispose($hImg) _GDIPlus_ImageSaveToFile($hImgre, $sFileSelectFolder & "\Thumbs\" & $sFileName & "New.jpg") _GDIPlus_ImageDispose($hImgre) Next MsgBox(32, "", "Alle Dateien sollten neu Skaliert sein") EndFunc Link to comment Share on other sites More sharing options...
UEZ Posted May 17, 2016 Share Posted May 17, 2016 Error 4 means porbably that the bitmap is not ok anymore -> _GDIPlus_ImageResize($hImage, ... This can be caused your loop which load images. Try this: expandcollapse popup#include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> DirChoose() Func DirChoose() Local Const $sMessage = "Wähle den Ordner aus" Global $sFileSelectFolder = FileSelectFolder($sMessage, "") MsgBox (0, "", $sFileselectfolder) If @error Then MsgBox($MB_SYSTEMMODAL, "", "Es wurde Kein Ordner ausgewählt!") Else ImageScan() EndIf EndFunc Func ImageScan() Global $ImageList = _FileListToArray($sFileSelectFolder, "*.jpg",1) MsgBox(0, "" ,$ImageList[0]) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Eingegebener Pfad ist ungültig!") Exit EndIf If @error = 2 Then MsgBox($MB_SYSTEMMODAL, "", "Eingegebener Filter ist ungültig!") Exit EndIf If @error = 3 Then MsgBox($MB_SYSTEMMODAL, "", "Keine Dateien gefunden!") Exit EndIf Resize() EndFunc Func Resize() _GDIPlus_Startup() DirCreate($sFileSelectFolder & "\Thumbs") Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" For $i = 1 to $ImageList[0] $hImg = _GDIPlus_ImageLoadFromFile($ImageList[$i]) If @error Then MsgBox(0, "ERROR", "Konnte die Datei " & $ImageList[$i] & " nicht als GDI+ Image laden!", 10) ContinueLoop EndIf $w = _GDIPlus_ImageGetWidth($hImg) $h = _GDIPlus_ImageGetHeight($hImg)/($w/200) _PathSplit($ImageList[$i],$sDrive,$sDir, $sFileName, $sExtension) $hImgre = _GDIPlus_ImageResize($hImg, 200,$h) If @error = 4 Then MsgBox(0, "", "") EndIf _GDIPlus_ImageDispose($hImg) _GDIPlus_ImageSaveToFile($hImgre, $sFileSelectFolder & "\Thumbs\" & $sFileName & "New.jpg") _GDIPlus_ImageDispose($hImgre) Next MsgBox(32, "", "Alle Dateien sollten neu Skaliert sein") EndFunc Probably one or more of your JPGs are not JPGs. 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...
DarkKeks Posted May 17, 2016 Author Share Posted May 17, 2016 Hi thats fast. Ok, i get the error you set. What i dont understand is when the script is in the directory i choose at the beginning it works and when it is in another directory and i choose the same path as before with the same JPG's it doesn't. Link to comment Share on other sites More sharing options...
UEZ Posted May 17, 2016 Share Posted May 17, 2016 (edited) 001s.jpg seems not to be an valid image which can be handled by GDI+. Probably it is damaged or some kind of data with the wrong extension. Edited May 17, 2016 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
DarkKeks Posted May 17, 2016 Author Share Posted May 17, 2016 Also, i have tried this. In the path C:\Users\Keks\Pictures\2015-12-12 are two images (001.jpg and 001s.jpg). Script path = C:\ and i choose ImagePath = C:\Users\Keks\Pictures\2015-12-12, with this settings the programs gives me the error above for the two image files. now Script path = C:\Users\Keks\Pictures\2015-12-12 and i choose the same image path (C:\Users\Keks\Pictures\2015-12-12), the Script does what it have to do. Why it only works when the script is in the same path as the choosen? Link to comment Share on other sites More sharing options...
UEZ Posted May 17, 2016 Share Posted May 17, 2016 You saved only the filename not the full path. Try Global $ImageList = _FileListToArray($sFileSelectFolder, "*.jpg",1,True) 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...
DarkKeks Posted May 17, 2016 Author Share Posted May 17, 2016 It works, so simple . Thank you very much. Link to comment Share on other sites More sharing options...
UEZ Posted May 17, 2016 Share Posted May 17, 2016 Gerne doch. 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...
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