Jump to content

I need help with picture resize


duni
 Share

Recommended Posts

Hi all! I am new in this programming language and i need some help. I'm trying to make a program that collects a number of pictures in a folder, it comes out the screen to give you the option to put a new resolution, the resize according to what you put and keep them all in a different folder and resized, but I can not . I have to use ImageMagick.

Let's see if someone can put a script on how to start or some script similar to what I have to do.

Thank you very much for the inconvenience and sorry for my bad english

Regards,

Duni!

P.D:It is similar to the script that I put, but need not be an image but were several.

ImageResize.au3

Link to comment
Share on other sites

Try this:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstants.au3>
#include <Misc.au3>
#Include <GuiMenu.au3>

Global $Picture, $Recentcount = 1, $Recent[2], $Edit = 0, $Place, $ImageWidth, $ImageHeight, $Resize = 0, $Sharpen = 0
Global $Output = @WindowsDir & "\Autoit.jpg"

;~ FileInstall("ImageMagickObject.dll", @SystemDir & "\ImageMagickObject.dll", 0)
;~ RunWait(@ComSpec & " /c regsvr32 /s ImageMagickObject.dll", @SystemDir, @SW_HIDE)

$GUI = GUICreate("Editor Imagen", 300, 300, 300, 200, $WS_OVERLAPPEDWINDOW)
$FileMenu = GUICtrlCreateMenu("Archivos")
$FileMenuOpen = GUICtrlCreateMenuItem("Abrir...", $FileMenu)
$FileMenuSave = GUICtrlCreateMenuItem("Guardar", $FileMenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$FileMenuSaveAs = GUICtrlCreateMenuItem("Guardar como..", $FileMenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$FileMenuRecentFiles = GUICtrlCreateMenu("Archivos recientes", $FileMenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$FileMenuSeparator1 = GUICtrlCreateMenuItem("", $FileMenu)
$FileMenuRenameFile = GUICtrlCreateMenuItem("Renombrar Archivo...", $FileMenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$FileMenuDeleteFile = GUICtrlCreateMenuItem("Borrar Archivo...", $FileMenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$FileMenuSeparator2 = GUICtrlCreateMenuItem("", $FileMenu)
$FileMenuExit = GUICtrlCreateMenuItem("Salir", $FileMenu)
$EditMenu = GUICtrlCreateMenu("Editar")
GUICtrlSetState(-1, $GUI_DISABLE)
$EditMenuResizeImage = GUICtrlCreateMenuItem("Resize Image...", $EditMenu)


_GDIPlus_Startup()
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
;~ $oImg = ObjCreate("ImageMagickObject.MagickImage.1")
GUISetState()
Global $Client = _WinGetClientPos(1)
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $FileMenuOpen
            $Image = FileOpenDialog("Choose file...", @DesktopCommonDir, "JPG (*.jpg)")
            If Not @error Then
                For $i = 1 To $Recentcount
                    If _GUICtrlMenu_GetItemText(GUICtrlGetHandle($FileMenuRecentFiles), $i - 1) = $Image Then
                        ExitLoop
                    EndIf
                    If $i = $Recentcount Then
                        $Recent[$Recentcount] = GUICtrlCreateMenuItem($Image, $FileMenuRecentFiles)
                        $Recentcount += 1
                        ReDim $Recent[$Recentcount + 1]
                    EndIf
                Next
                MenuEnable()
                Preview($Image)
            EndIf
        Case $FileMenuSave
            If FileExists(@WindowsDir & "\Autoit.jpg") Then FileCopy(@WindowsDir & "\Autoit.jpg", $Place, 9)
        Case $FileMenuSaveAs
            If FileExists(@WindowsDir & "\Autoit.jpg") Then
                $Save = FileSaveDialog("Escoge donde guardarla", @DesktopCommonDir, "JPG - JPEG Files (*.jpg)")
                If Not StringInStr($Save, ".jpg") Then $Save &= ".jpg"
                FileCopy(@WindowsDir & "\Autoit.jpg", $Save, 9)
                $Place = $Save
            EndIf
        Case $FileMenuRenameFile
            $SplitPlace = StringSplit($Place, "\", 1)
            $Input = InputBox("Renombrar archivo", "New name :", $SplitPlace[UBound($SplitPlace) - 1], "", 200, 130)
            If Not @error And $Input <> "" Then
                $TrimPlace = StringTrimRight($Place, StringLen($SplitPlace[UBound($SplitPlace) - 1]))
                MsgBox("", "", $TrimPlace & $Input)
                FileMove($Place, $TrimPlace & $Input, 1)
            EndIf
        Case $FileMenuDeleteFile
            $Delete = MsgBox(36, "Borrar Archivo", "Estas seguro de querer borrar el archivo?")
            If $Delete = 6 Then FileDelete($Place)
        Case $FileMenuExit
            Exit
        Case $EditMenuResizeImage
            ResizeGUI()
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            For $i = 1 To $Recentcount - 1
                If $Recent[$i] = $msg Then
                    $Image = _GUICtrlMenu_GetItemText(GUICtrlGetHandle($FileMenuRecentFiles), $i - 1)
                    Preview($Image)
                EndIf
            Next
    EndSwitch
WEnd
Exit
Func Preview($ImageName, $Edit = 0)
    Local $hImage = _GDIPlus_ImageLoadFromFile($ImageName)
    Global $ImageWidth = _GDIPlus_ImageGetWidth($hImage)
    Global $ImageHeight = _GDIPlus_ImageGetHeight($hImage)
    _GDIPlus_ImageDispose($hImage)
    If $Picture <> "" Then GUICtrlDelete($Picture)
    $Picture = GUICtrlCreatePic($ImageName, 0, 0, $ImageWidth, $ImageHeight)
    WinMove($GUI, "", Default, Default, $ImageWidth, $ImageHeight)
    Local $ClientSize = WinGetClientSize($GUI)
    WinMove($GUI, "", (@DesktopWidth / 2) - ($ImageWidth / 2), (@DesktopHeight / 2) - ($ImageHeight / 2), $ImageWidth + ($ImageWidth - $ClientSize[0]), $ImageHeight + ($ImageHeight - $ClientSize[1]))
    Global $Image = $ImageName
    If Not $Edit Then
        Global $Place = $Image
        FileCopy($Place, @WindowsDir & "\Autoit.jpg", 9)
    EndIf
EndFunc   ;==>Preview

Func ResizeGUI()
    $ResizeForm = GUICreate("Cambiar tamaño imagen", 210, 110, -1, -1)
    $ResizeLabel1 = GUICtrlCreateLabel("Tamaño :   " & $ImageWidth & " x " & $ImageHeight, 16, 16, 137, 17)
    $ResizeInput1 = GUICtrlCreateInput("", 56, 40, 41, 21)
    $ResizeLabel2 = GUICtrlCreateLabel("Ancho :", 10, 48, 38, 17)
    $ResizeLabel3 = GUICtrlCreateLabel("Alto :", 115, 48, 41, 17)
    $ResizeInput2 = GUICtrlCreateInput("", 152, 40, 41, 21)
    $ResizeButton1 = GUICtrlCreateButton("OK", 16, 72, 83, 25, 0)
    $ResizeButton2 = GUICtrlCreateButton("Cancelar", 112, 72, 83, 25, 0)
    GUISetState(@SW_SHOW, $ResizeForm)
    While 1
        $msg = GUIGetMsg(1)
        If $msg[0] = $ResizeButton1 Then
            $NewWidth = GUICtrlRead($ResizeInput1)
            $NewHeight = GUICtrlRead($ResizeInput2)
            $Resize = 1
            ExitLoop
        ElseIf $msg[0] = $ResizeButton2 Or $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $ResizeForm Then
            ExitLoop
        ElseIf $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $GUI Then
            Exit
        EndIf
    WEnd
    GUIDelete($ResizeForm)
    If $Resize = 1 Then
        Resize($Image, $Output, $NewWidth, $NewHeight)
        barra()
         Preview($Output, 1)
        $Resize = 0
    EndIf
EndFunc   ;==>ResizeGUI

Func MenuEnable()
    GUICtrlSetState($FileMenuSave, $GUI_ENABLE)
    GUICtrlSetState($FileMenuSaveAs, $GUI_ENABLE)
    GUICtrlSetState($FileMenuRecentFiles, $GUI_ENABLE)
    GUICtrlSetState($FileMenuRenameFile, $GUI_ENABLE)
    GUICtrlSetState($FileMenuDeleteFile, $GUI_ENABLE)
    GUICtrlSetState($EditMenu, $GUI_ENABLE)
EndFunc   ;==>MenuEnable
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "COM Error Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.descripcion is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescriction:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.numero is: " & @TAB & $HexNumber & @CRLF & _
            "err.ultimodllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.lineascript is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.codigo is: " & @TAB & $oMyError.source & @CRLF & _
            "err.archivoayuda is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.ayudacontextual is: " & @TAB & $oMyError.helpcontext _
            )
    SetError(1)
EndFunc   ;==>MyErrFunc

Func GetClientPos($wTitle = "")
    Local $cPos[6]
    $wPos = WinGetPos($wTitle)
    $cPos[0] = $wPos[0] + $Client[0]
    $cPos[1] = $wPos[1] + $Client[1]
    $cPos[2] = ($wPos[0] + $wPos[2]) - $Client[2]
    $cPos[3] = ($wPos[1] + $wPos[3]) - $Client[3]
    $cPos[4] = $cPos[2] - $cPos[0]
    $cPos[5] = $cPos[3] - $cPos[1]
    Return $cPos
EndFunc   ;==>GetClientPos

Func _WinGetClientPos($fAbsolute = 0)
    Local $cPos = DllStructCreate("long;long;long;long"), $hWin = WinGetHandle("")
    DllCall("user32.dll", "int", "GetClientRect", "hwnd", $hWin, "ptr", DllStructGetPtr($cPos))
    Local $cPos2[4] = [DllStructGetData($cPos, 1), DllStructGetData($cPos, 2), DllStructGetData($cPos, 3), DllStructGetData($cPos, 4)]
    If $fAbsolute Then
        Local $MousePosSav = MouseGetPos()
        Local $MouseModeSav = Opt("MouseCoordMode", 2)
        MouseMove(0, 0, 0)
        Opt("MouseCoordMode", 1)
        Local $avRET = MouseGetPos()
        Opt("MouseCoordMode", $MouseModeSav)
        MouseMove($MousePosSav[0], $MousePosSav[1], 0)
        $wPos = WinGetPos("")
        $cPos2[0] = $avRET[0] - $wPos[0]
        $cPos2[1] = $avRET[1] - $wPos[1]
        $cPos2[2] = ($wPos[0] + $wPos[2]) - ($avRET[0] + $cPos2[2])
        $cPos2[3] = ($wPos[1] + $wPos[3]) - ($avRET[1] + $cPos2[3])
    EndIf
    Return $cPos2
EndFunc   ;==>_WinGetClientPos


Func Resize($sInFile, $sOutFile, $sWidth, $sHeight,  $iInterpolationMode = 7)
;~     $oImg.Convert($sInFile, "-resize", $sWidth & "x" & $sHeight & "!", $sOutFile)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sInFile)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $sWidth, "int", $sHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap = $aResult [6]
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hCtxt , "int", $iInterpolationMode)
    _GDIPlus_GraphicsDrawImageRect($hCtxt, $hImage, 0, 0, $sWidth, $sHeight)
    _GDIPlus_ImageSaveToFile($hBitmap, $sOutFile)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_ImageDispose($hImage)
EndFunc   ;==>Resize

func barra()
ProgressOn("Progress Bar", "", "Trabajando..")

For $i = 0 To 100
    ProgressSet($i)
    Sleep(5)
Next

ProgressSet(100, "Hecho!")
Sleep(750)
ProgressOff()
EndFunc

Br,

UEZ

Edited 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

I wrote this function a while ago.

#include <File.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()

Global $folder = FileSelectFolder("Select folder with pictures", "", 4) & "\"
Global $outfolder = @ScriptDir & "\Resized"
If @error Then Exit MsgBox(0, "Information", "Nothing selected - closing program", 10)
Global $aFiles = _FileListToArray($folder, "*.???", 0)
For $i = 1 To $aFiles[0]
    If StringRegExp($aFiles[$i], "(?i).*\.png|.*\.jpg|.*\.bmp", 0) Then ResizeImage($folder & $aFiles[$i], 32, 32, $outfolder, -1)
Next
_GDIPlus_Shutdown()
ShellExecute($outfolder)
Exit

;======================================================================================
; Function Name:        ResizeImage
; Description:          Loads an image and scales it to desired width or height
;
; Parameters:           $fImage:                image file to be loaded
;                               $iW:                    new image width. If $iW = 0 then default values is 96
;                               $iH:                        new image height. If $iH = 0 then default values is 96
;                               $fDestFolder:       destination folder where the scaled image should be saved to
;                               $fExt:                  image output format (can be jpg, png, bmp, gif, tiff) - default is PNG, -1 to keep extension
;                               $fPart:                 filename part to separate it from orignal name. Default is .resized. -> filename.resized.ext
;
; Requirement(s):       GDIPlus.au3
; Return Value(s):  Success: True, Error: see below
; Error codes:          1: no filename given
;                               2:  filename doesn't exist
;                               3: image couldn't be resized
;                               4: resized image couldn't be saved
;
; Author(s):                UEZ
; Version:                  v0.80 Build 2011-08-29 Beta
;=======================================================================================
Func ResizeImage($fImage, $iW, $iH, $fDestFolder, $fExt = "png", $fPart = ".resized.")
    If $fImage = "" Then Return SetError(1, 0, 0)
    If Not FileExists($fImage) Then Return SetError(2, 0, 0)
    Local $iOutputFormats = "jpg,png,bmp,gif,tif"
    If Not StringInStr($iOutputFormats, $fExt)  Then
        If $fExt <> -1 Then
            $fExt = "png"
        Else
            If Not StringInStr($iOutputFormats, StringRight($fImage, 3)) Then
                $fExt = "png"
            Else
                $fExt = StringRight($fImage, 3)
            EndIf
        EndIf
    EndIf
    Local $fName = StringRegExpReplace($fImage, ".*\\(.*).{4}", "$1")
    Local $declared = True
    If Not $ghGDIPDll Then
        _GDIPlus_Startup()
        $declared = False
    EndIf
    Local $hImageFromFile = _GDIPlus_ImageLoadFromFile($fImage)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImageFromFile)
    Local $iHeight = _GDIPlus_ImageGetHeight($hImageFromFile)
    Local $x, $y
    If Not $iW And Not $iH Then
        $iW = 96
        $iH = 96
    ElseIf $iW And Not $iH Then
        $x = $iW / $iWidth
        $iH = Int($iHeight * $x)
    ElseIf Not $iW And $iH Then
        $y = $iH / $iHeight
        $iW = Int($iWidth * $y)
    EndIf
    Local $hImageThumbnail = DllCall($ghGDIPDll, "uint", "GdipGetImageThumbnail", "handle", $hImageFromFile, "uint", $iW, "uint", $iH, "int*", 0, "ptr", 0, "ptr", 0)
    If @error Then
        _GDIPlus_ImageDispose($hImageFromFile)
        If Not $declared Then _GDIPlus_Shutdown()
        Return SetError(3, 0, 0)
    EndIf
    $hImageThumbnail = $hImageThumbnail[4]
    If Not FileExists($fDestFolder) Then DirCreate($fDestFolder)
    If $fPart = "" Then $fPart = "."
    If Not _GDIPlus_ImageSaveToFile($hImageThumbnail, $fDestFolder & "\" & $fName & $fPart & $fExt) Then
        _GDIPlus_ImageDispose($hImageFromFile)
        _GDIPlus_ImageDispose($hImageThumbnail)
        If Not $declared Then _GDIPlus_Shutdown()
        Return SetError(4, 0, 0)
    EndIf
    _GDIPlus_ImageDispose($hImageFromFile)
    _GDIPlus_ImageDispose($hImageThumbnail)
    If Not $declared Then _GDIPlus_Shutdown()
    Return True
EndFunc

Might be helpful for you.

Br,

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

Yeah, that function is where I drew but I need one that you can choose your pixels that you want ,not those who enter the program, on a screen that asks you the width and height.

Are you understand me??

Link to comment
Share on other sites

I have this scrip and I still don´t work . I need to do what i put in the previous post, resize the pictures but putting in a different window the new pixels. I would appreciate if someone help me because its vital for me do this.

#include <File.au3>
#include <GDIPlus.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <Misc.au3>
#Include <GuiMenu.au3>
_GDIPlus_Startup()
Global $folder = FileSelectFolder("Select folder with pictures", "", 4) & "\"
Global $fDestfolder = @ScriptDir & "\Resized"
If @error Then Exit MsgBox(0, "Information", "Nothing selected - closing program", 10)
Global $aFiles = _FileListToArray($folder, "*.???", 0)
For $i = 1 To $aFiles[0]
    If StringRegExp($aFiles[$i], "(?i).*\.png|.*\.jpg|.*\.bmp", 0) Then ResizeImage($folder & $aFiles[$i], 0, 0, $fDestfolder, -1)
Next
_GDIPlus_Shutdown()
ShellExecute($outfolder)
Exit
;======================================================================================
; Function Name:        ResizeImage
; Description:        Loads an image and scales it to desired width or height
;
; Parameters:          $fImage:             image file to be loaded
;                              $iW:                 new image width. If $iW = 0 then default values is 96
;                              $iH:                     new image height. If $iH = 0 then default values is 96
;                              $fDestFolder:       destination folder where the scaled image should be saved to
;                              $fExt:                 image output format (can be jpg, png, bmp, gif, tiff) - default is PNG, -1 to keep extension
;                              $fPart:               filename part to separate it from orignal name. Default is .resized. -> filename.resized.ext
;
; Requirement(s):      GDIPlus.au3
; Return Value(s):  Success: True, Error: see below
; Error codes:        1: no filename given
;                              2:  filename doesn't exist
;                              3: image couldn't be resized
;                              4: resized image couldn't be saved
;
; Author(s):                UEZ
; Version:                v0.80 Build 2011-08-29 Beta
;=======================================================================================
Func ResizeImage($fImage, $iW, $iH, $fDestFolder, $fExt = "png", $fPart = ".resized.")
    If $fImage = "" Then Return SetError(1, 0, 0)
    If Not FileExists($fImage) Then Return SetError(2, 0, 0)
    Local $iOutputFormats = "jpg,png,bmp,gif,tif"
    If Not StringInStr($iOutputFormats, $fExt)  Then
        If $fExt <> -1 Then
            $fExt = "png"
        Else
            If Not StringInStr($iOutputFormats, StringRight($fImage, 3)) Then
                $fExt = "png"
            Else
                $fExt = StringRight($fImage, 3)
            EndIf
        EndIf
    EndIf
    Local $fName = StringRegExpReplace($fImage, ".*\\(.*).{4}", "$1")
    Local $declared = True
    If Not $ghGDIPDll Then
        _GDIPlus_Startup()
        $declared = False
    EndIf
    Local $hImageFromFile = _GDIPlus_ImageLoadFromFile($fImage)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImageFromFile)
    Local $iHeight = _GDIPlus_ImageGetHeight($hImageFromFile)
    Local $x, $y
    If Not $iW And Not $iH Then
  ResizeGui($iW,$iH)
    EndIf
    Local $hImageThumbnail = DllCall($ghGDIPDll, "uint", "GdipGetImageThumbnail", "handle", $hImageFromFile, "uint", $iW, "uint", $iH, "int*", 0, "ptr", 0, "ptr", 0)
    If @error Then
        _GDIPlus_ImageDispose($hImageFromFile)
        If Not $declared Then _GDIPlus_Shutdown()
        Return SetError(3, 0, 0)
    EndIf
    $hImageThumbnail = $hImageThumbnail[4]
    If Not FileExists($fDestFolder) Then DirCreate($fDestFolder)
    If $fPart = "" Then $fPart = "."
    If Not _GDIPlus_ImageSaveToFile($hImageThumbnail, $fDestFolder & "\" & $fName & $fPart & $fExt) Then
        _GDIPlus_ImageDispose($hImageFromFile)
        _GDIPlus_ImageDispose($hImageThumbnail)
 
        If Not $declared Then _GDIPlus_Shutdown()
        Return SetError(4, 0, 0)
    EndIf
    _GDIPlus_ImageDispose($hImageFromFile)
    _GDIPlus_ImageDispose($hImageThumbnail)
    If Not $declared Then _GDIPlus_Shutdown()
    Return True
EndFunc
func barra()
ProgressOn("Progress Bar", "", "Trabajando...")
For $i = 0 To 100
ProgressSet($i)
Sleep(5)
Next
ProgressSet(100, "Hecho!")
Sleep(750)
ProgressOff()
EndFunc
Func ResizeGui($iW, $iH)
$ResizeForm = GUICreate("Redimensionar Imagen", 210, 110, -1, -1)
    $ResizeInput1 = GUICtrlCreateInput("", 56, 40, 41, 21)
    $ResizeLabel2 = GUICtrlCreateLabel("Ancho :", 10, 48, 38, 17)
    $ResizeLabel3 = GUICtrlCreateLabel("Alto :", 115, 48, 41, 17)
    $ResizeInput2 = GUICtrlCreateInput("", 152, 40, 41, 21)
    $ResizeButton1 = GUICtrlCreateButton("OK", 16, 72, 83, 25, 0)
    $ResizeButton2 = GUICtrlCreateButton("Cancelar", 112, 72, 83, 25, 0)
    While 1
        $msg = GUIGetMsg(1)
        If $msg[0] = $ResizeButton1 Then
            $iW = GUICtrlRead($ResizeInput1)
            $iH = GUICtrlRead($ResizeInput2)
            ExitLoop
        ElseIf $msg[0] = $ResizeButton2 Or $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $ResizeForm Then
            ExitLoop
        ElseIf $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $GUI Then
            Exit
        EndIf
    WEnd
    Return ($iW, $iH)
GUIDelete($ResizeForm)
EndFunc

Thks!!!!!

Edited by duni
Link to comment
Share on other sites

Okay, you got something. Now I only need to instead of me screen out of pixels for each picture, leave only once. I do, with one for? Any suggestions? Thank you for the inconvenience!

I leave here the script:

;======================================================================================

; Function Name: ResizeImage

; Description: Loads an image and scales it to desired width or height

;

; Parameters: $fImage: image file to be loaded

; $iW: new image width. If $iW = 0 then default values is 96

; $iH: new image height. If $iH = 0 then default values is 96

; $fDestFolder: destination folder where the scaled image should be saved to

; $fExt: image output format (can be jpg, png, bmp, gif, tiff) - default is PNG, -1 to keep extension

; $fPart: filename part to separate it from orignal name. Default is .resized. -> filename.resized.ext

;

; Requirement(s): GDIPlus.au3

; Return Value(s): Success: True, Error: see below

; Error codes: 1: no filename given

; 2: filename doesn't exist

; 3: image couldn't be resized

; 4: resized image couldn't be saved

;

; Author(s): UEZ

; Version: v0.80 Build 2011-08-29 Beta

;=======================================================================================

#include <File.au3>

#include <GDIPlus.au3>

#include <GUIConstants.au3>

_GDIPlus_Startup()

Global $folder = FileSelectFolder("Select folder with pictures", "", 4) & "\"

Global $outfolder = @ScriptDir & "\Resized"

If @error Then Exit MsgBox(0, "Information", "Nothing selected - closing program", 10)

Global $aFiles = _FileListToArray($folder, "*.???", 0)

For $i = 1 To $aFiles[0]

If StringRegExp($aFiles[$i], "(?i).*\.png|.*\.jpg|.*\.bmp", 0) Then ResizeImage($folder & $aFiles[$i], 0, 0, $outfolder, -1)

Next

_GDIPlus_Shutdown()

ShellExecute($outfolder)

Exit

Func ResizeImage($fImage, $iW, $iH, $fDestFolder, $fExt = "jpg", $fPart = ".resized.")

If $fImage = "" Then Return SetError(1, 0, 0)

If Not FileExists($fImage) Then Return SetError(2, 0, 0)

Local $iOutputFormats = "jpg,png,bmp,gif,tif"

If Not StringInStr($iOutputFormats, $fExt) Then

If $fExt <> -1 Then

$fExt = "png"

Else

If Not StringInStr($iOutputFormats, StringRight($fImage, 3)) Then

$fExt = "png"

Else

$fExt = StringRight($fImage, 3)

EndIf

EndIf

EndIf

Local $fName = StringRegExpReplace($fImage, ".*\\(.*).{4}", "$1")

Local $declared = True

If Not $ghGDIPDll Then

_GDIPlus_Startup()

$declared = False

EndIf

Local $hImageFromFile = _GDIPlus_ImageLoadFromFile($fImage)

Local $iWidth = _GDIPlus_ImageGetWidth($hImageFromFile)

Local $iHeight = _GDIPlus_ImageGetHeight($hImageFromFile)

Local $x, $y

If Not $iW And Not $iH Then

$ResizeForm = GUICreate("Cambiar tamaño imagen", 210, 110, -1, -1)

$ResizeLabel1 = GUICtrlCreateLabel("Tamaño : " & $iWidth & " x " & $iHeight, 16, 16, 137, 17)

$ResizeInput1 = GUICtrlCreateInput("", 56, 40, 41, 21)

$ResizeLabel2 = GUICtrlCreateLabel("Ancho :", 10, 48, 38, 17)

$ResizeLabel3 = GUICtrlCreateLabel("Alto :", 115, 48, 41, 17)

$ResizeInput2 = GUICtrlCreateInput("", 152, 40, 41, 21)

$ResizeButton1 = GUICtrlCreateButton("OK", 16, 72, 83, 25, 0)

$ResizeButton2 = GUICtrlCreateButton("Cancelar", 112, 72, 83, 25, 0)

GUISetState(@SW_SHOW, $ResizeForm)

While 1

$msg = GUIGetMsg(1)

If $msg[0] = $ResizeButton1 Then

$NewWidth = GUICtrlRead($ResizeInput1)

$NewHeight = GUICtrlRead($ResizeInput2)

ExitLoop

ElseIf $msg[0] = $ResizeButton2 Or $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $ResizeForm Then

ExitLoop

ElseIf $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $GUI Then

Exit

EndIf

WEnd

GUIDelete($ResizeForm)

EndIf

Local $hImageThumbnail = DllCall($ghGDIPDll, "uint", "GdipGetImageThumbnail", "handle", $hImageFromFile, "uint", $NewWidth, "uint", $NewHeight, "int*", 0, "ptr", 0, "ptr", 0)

If @error Then

_GDIPlus_ImageDispose($hImageFromFile)

If Not $declared Then _GDIPlus_Shutdown()

Return SetError(3, 0, 0)

EndIf

$hImageThumbnail = $hImageThumbnail[4]

If Not FileExists($fDestFolder) Then DirCreate($fDestFolder)

If $fPart = "" Then $fPart = "."

If Not _GDIPlus_ImageSaveToFile($hImageThumbnail, $fDestFolder & "\" & $fName & $fPart & $fExt) Then

_GDIPlus_ImageDispose($hImageFromFile)

_GDIPlus_ImageDispose($hImageThumbnail)

If Not $declared Then _GDIPlus_Shutdown()

Return SetError(4, 0, 0)

EndIf

_GDIPlus_ImageDispose($hImageFromFile)

_GDIPlus_ImageDispose($hImageThumbnail)

If Not $declared Then _GDIPlus_Shutdown()

Return True

EndFunc

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...