Auto rotate image baised on EXIF data.
Auto brightens dark areas
Auto resize shrinks to typical 3MP image
Recompresses jpg files to 70% quality for web use.
Dumps processed files in a dir on the desktop.
Grabed Code From my batch m2v maker
http://www.autoitscript.com/forum/index.php?showtopic=58691
and the ImageMagick Object
http://www.autoitscript.com/forum/index.php?showtopic=49065
AutoIt
#include <Array.au3> ; Basic ImageMagick Vars Global $ret = 0 Global $info Global $msgs Global $elem Global $sMsgs Global Const $ERROR_SUCCESS = 0 ChkImageMagickInstall() ; ImageMagick Error handler Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") Global $img = ObjCreate("ImageMagickObject.MagickImage.1") ;Autoit Variables Global $filelist[1] $filelist[0] = 0 Global $filetype = "*.jpg" Global $OutDir = @DesktopDir & "\" & @YEAR & "-" & @MON ChkCmd() ProcessImages() ; Install Imagemagick Func ChkImageMagickInstall() If DirGetSize(@ProgramFilesDir & "\ImageMagick-6.4.7-Q16") == -1 Then ToolTip("Installing Image Processing Tools") FileInstall("ImageMagick-6.4.7-6-Q16-windows-dll.exe", "install.exe") RunWait("install.exe" & " /VERYSILENT" & ' /COMPONENTS="install_magick_dll"') ToolTip("Tools Installed") FileInstall("ImageMagickObject.dll", @ProgramFilesDir & "\ImageMagick-6.4.7-Q16\ImageMagickObject.dll") FileInstall("MagickCMD.exe", @ProgramFilesDir & "\MagickCMD.exe") Sleep(1000) RunWait(@ComSpec & " /c " & 'Regsvr32 /s "' & @ProgramFilesDir & '\ImageMagick-6.4.7-Q16\ImageMagickObject.dll"', "", @SW_HIDE) Sleep(1000) ToolTip("") EndIf EndFunc ;Grab EXE Drag-n-Droped files/dir's Func ChkCmd() ;Files where dropped onto exe If $CmdLine[0] > 0 Then ArrayToFileList($CmdLine) EndIf EndFunc ;==>ChkCmd ;add from given array to Filelist Func ArrayToFileList($CmdLine) Local $dirbit = 0 For $x = 1 To $CmdLine[0] Step +1 ;run though all files droped and look for dir's If StringInStr(FileGetAttrib($CmdLine[$x]), "D") Then $dirbit += 1 FileListFromDir($CmdLine[$x]) ;parce dir looking for file of that extenstion Else ;add file to list _ArrayAdd($filelist, $CmdLine[$x]) $filelist[0] += 1 EndIf Next EndFunc ;==>ArrayToFileList ;add to array, list of files in a dir Func FileListFromDir($dir) ;search for the first file with the correct file extenstion Local $file, $search = FileFindFirstFile($dir & "\" & $filetype) ; Check if the search was successful If $search = -1 Then MsgBox(0x40000, "Error", "No Picture " & $filetype & " files found") EndIf ;add found files to array While 1 $file = FileFindNextFile($search) If @error Then ExitLoop EndIf ;Add file to array _ArrayAdd($filelist, $dir & "\" & $file) $filelist[0] += 1 WEnd FileClose($search) ; Close the search handle EndFunc ;==>FileListFromDir Func ProcessImages() ProgressOn("Image Processor", "Total of " & $filelist[0] & " images loaded for processing") DirCreate($OutDir) While DirGetSize($OutDir) == -1 Sleep(250) WEnd Sleep(250) $step = 100 / $filelist[0] $increment = $step While $filelist[0] > 0 Local $filein = $filelist[1] Local $fileout = ChangeOutputDir($filelist[1]) ProgressSet($increment, Round($increment) & " percent") _ImageMagick_Quality($filein, "70", $fileout) If @error Then ExitLoop _ArrayDelete($filelist, 1) $filelist[0] -= 1 $increment += $step WEnd ProgressSet(100 , "Done", "Complete") ShellExecute($OutDir) Sleep(500) ProgressOff() EndFunc ; Error event Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"ImageMagick Error", "There was an ImageMagick error!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns EndFunc Func _ImageMagick_Quality($sInFile, $sQuality, $sOutFile) $ret = $img.Convert($sInFile, _ "-auto-orient", " ", _ "-quality",$sQuality, _ "-sigmoidal-contrast", "2,0%", _ "-filter","Lagrange", _ "-resize","2048x2048>", _ $sOutFile) Return $ret EndFunc ;change string to output dir right before it goes to HCenc.exe Func ChangeOutputDir($fileout) Local $temp = StringSplit($fileout, "\") $fileout = $OutDir & "\" & $temp[$temp[0]] Return $fileout EndFunc
Edit 12-12-2008:
Using -sigmoidal-contrast for image brightness
Added in Resize
Edited by mikeytown2, 12 December 2008 - 08:54 AM.





