Jump to content

extract image dimensions


Recommended Posts

i have many images of the same size with black backgrounds. it's sword image frames that have to be cropped to the edges of the swords images removing empty space and reducing the image size. the script has to batch crop all images from a chosen folder and it has to generate image placement text files with x y co ords needed to re center the images of swords that when cropped without placement x y values cannot animate correctly because of variation of image sizes that previously (before cropping) were the same and centered. (no longer centered when cropped)

placement files are text files that contain the images x y positions and that have the same filename as the corresponding images

eg: placement text file of cropped image1.png contains:

image1.txt

160

65

 

etc

 

the same thing for all cropped images

Edited by way1000
Link to comment
Share on other sites

  • Moderators

@way1000 you have told us what you want (great start). However this is not a forum where you put in a request and someone barfs up code for you. What have you tried on your own, through searching the forum, Google, the Help file or the Wiki?

 

Edit: D'oh, too slow :)

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

thank you all for your replies

i cant program a image cropper right now, it's very difficult i think

this is now slightly off topic but is there a way to batch extract image dimensions (in a folder) , height and width and save as text files with the original image file names as .txt

thanks in advance

 

 

Link to comment
Share on other sites

  • Moderators
33 minutes ago, way1000 said:

i cant program a image cropper right now, it's very difficult i think

@way1000 this forum is dedicated to helping people learn to script, as well as helping them to improve their own scripts. If you have neither the time nor the desire to learn how to do this, a site like freelancer.com may be your best option

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

4 hours ago, way1000 said:

many images of the same size with black backgrounds. ..

that have to be cropped .. removing empty space and reducing the image size.

batch crop all images from a chosen folder ..

Maybe you should look first at some program to do graphics,

like irfanview, ImageMagick / GraphicsMagick or gimp.

They all have features for automating / batch-runs.

-HaJo

Link to comment
Share on other sites

i edited a script but i cant seem to make it so it writes the height and width of images on a folder in text files which have to be txt files of the same name as image file names

i tried to add everything i found in the help file that could make it work, but i got stuck so i need help

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <WinAPI.au3>

Global $g_idMemo

Example()

Func Example()
    Local $hImage, $hGUI, $hDC, $tSize
    Local $sPath = "C:\tmp\iddle\iddle 1"
    Local $file = FileOpen($sPath & ".txt", 1)

    $hGUI = GUICreate("ImageList Get Icon SizeEx", 400, 300)
    $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 266, 0)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)


; Load images
    $hImage = $sPath & ".png"
    ;_GUIImageList_AddBitmap($hImage, $sPath & ".png")

    _WinAPI_ReleaseDC($hGUI, $hDC)

    ; Show image list icon size
    $tSize = _GUIImageList_GetIconSizeEx($hImage)
    MemoWrite("Image width : " & DllStructGetData($tSize, "X"))
    MemoWrite("Image height: " & DllStructGetData($tSize, "Y"))

FileWriteLine($file, $tSize)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

 

Edited by way1000
Link to comment
Share on other sites

Use these functions:

_GDIPlus_ImageGetWidth() / _GDIPlus_ImageGetHeight() / _GDIPlus_ImageGetDimension()
_GDIPlus_ImageResize()
_GDIPlus_GraphicsDrawImageRectRect() ;to crop image
_GDIPlus_ImageLoadFromFile()
_GDIPlus_ImageSaveToFile()
_FileListToArray() / _FileListToArrayRec() ;to load the images

 

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

thanks a lot

i tried to create it differently but i'm stuck again with 1 error message

#include <GDIPlus.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

Example()

Func Example()
    Local $aDim, $hImage, $sFile, $iX, $iY
    Local $aScriptDir = _FileListToArray("C:\tmp\iddle\iddle 1")

    ;instead of test.txt this has to be text files that take the names of the image files
    Local $sfile = FileOpen("test.txt", 1)

    _GDIPlus_Startup()

    $hImage = $aScriptDir & "*.png"
    $iX = _GDIPlus_ImageGetWidth($hImage)
    $iY = _GDIPlus_ImageGetHeight($hImage)

    If @error Or Not $hImage Then
        MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!")
    Else
        $aDim = _GDIPlus_ImageGetDimension($hImage)
        FileWriteLine($MB_ICONINFORMATION, $sFile & @CRLF & @CRLF & "Width = " & $iX & @CRLF & "Height = " & $iY)
        _GDIPlus_ImageDispose($hImage)
        FileClose($sfile)
    EndIf

    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

Link to comment
Share on other sites

try this script:

#include <GDIPlus.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

Example()

Func Example()
    Local $aDim, $hImage, $hFile, $iX, $iY
    Local $sSearchPath = "C:\tmp\iddle\iddle 1" ;path where the files stored
    Local $hFile = FileOpen("test.txt", $FO_OVERWRITE) ;overwrite so after script runs only files of this run are in script
    Local $aFiles = _FileListToArray($sSearchPath, "*.png", $FLTA_FILES, True)
    If @error Then
        FileWriteLine($hFile, "No files found Error "&@error)
    Else
        _GDIPlus_Startup()
        For $i = 1 To $aFiles[0]
            ConsoleWrite($aFiles[$i] & @CRLF)
            $hImage = _GDIPlus_ImageLoadFromFile($aFiles[$i]) ;load image from file
            $iX = 0
            $iY = 0
            $iX = _GDIPlus_ImageGetWidth($hImage)
            $iY = _GDIPlus_ImageGetHeight($hImage)
            FileWriteLine($hFile, $aFiles[$i] & @TAB & "Width = " & $iX & @TAB & "Height = " & $iY)
            If $iX = 0 Or $iY = 0 Then MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", $aFiles[$i]&@CRLF&@CRLF&"This file isn't supported by GDIPlus!")
            _GDIPlus_ImageDispose($hImage)
        Next
        FileClose($hFile)
        _GDIPlus_Shutdown()
    EndIf
    ShellExecute('test.txt')
EndFunc   ;==>Example

as your script had many mistakes i also suggest: read about the used funcs in the helpfile

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...