way1000

extract image dimensions

14 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

@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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

GDIPlus can do what you want probably, for me personally I usually use IrfanView and it has batch features and can be cmd driven so automation via AutoIt with CMD parameters is possible. 

Share this post


Link to post
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

 

 

Share this post


Link to post
Share on other sites
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


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

18 hours ago, way1000 said:

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

 ImageMagick:   identify

GraphicsMagick:  gm identify

Also, look for ExifInfo / ExifTool

Edited by hajo4

-HaJo

Share this post


Link to post
Share on other sites

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

how can i make the above script work?

i get

"Error", "This file isn't supported by GDIPlus!"

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

thanks a lot

Share this post


Link to post
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