Page 1 of 1

How to read width and height parameters from an image?

Posted: Fri Feb 21, 2014 10:36 pm
by NubeCheCorre
Hi!,

I use FileRequest() function to select one or more image files from a directory.. Then I need to know the width and the height of every image (they will have the same width and height but I don't know the size) as I need to create one brush and copy them one side by side.. I looked deeply in the doc but I didn't find any Get Function about width and height or pixel information..

Any help is appreciated :)

Re: How to read width and height parameters from an image?

Posted: Sat Feb 22, 2014 4:29 am
by PEB
The table returned by IsPicture() should do what you want.

Re: How to read width and height parameters from an image?

Posted: Sat Feb 22, 2014 11:19 am
by NubeCheCorre
Thank You!! I totally missed that function! thanks! :)

Re: How to read width and height parameters from an image?

Posted: Sat Feb 22, 2014 8:40 pm
by NubeCheCorre
I tried but I still have some problem... it seems that the table is empty, very strange.. here the code I wrote to test the function:

Code: Select all


@VERSION 5,0
@APPTITLE "Join Files"
@APPVERSION "$VER: Hollywood 5.0 (12-March-12)"
@DISPLAY {Title = "Join Files"}
@SCREEN {Mode = "ask", Width = 640, Height = 480}

pattern$ = "jpg|jpeg|bmp|tif|gif|png"

title$ = "Choose files"

tempfile$ = "temp.png"

f$ = FileRequest(title$,pattern$,#REQ_MULTISELECT)

NPrint("Path:", PathPart(f$[0]))

NPrint("Files selected:", ListItems(f$) - 1)

While f$[c] <> ""
	NPrint(FilePart(f$[c]))
	c = c + 1
Wend

	d = 1 ;  id brush counter
	
While f$[e] <> ""
	LoadBrush(d,f$[e])
	ret_val, table$ = IsPicture(f$[e])
If ret_val = True
	NPrint("The file is an image? :", ret_val)
	NPrint("Width:", table$[e])
	NPrint("Height:", table$[e])
	NPrint("Alpha:", table$[e])
	NPrint("Vector:", table$[e])
Else
	NPrint("The file is not an image...")
EndIf 
	d = d + 1 ;counter
	e = e + 1 ;counter
Wend

WaitLeftMouse()
End()

That's the error that Hollywood report to me:
Error in line 32 (main_util.hws): Table field 0 was not initialized!

Re: How to read width and height parameters from an image?

Posted: Sun Feb 23, 2014 10:10 am
by patizak
Hi
Try this

Code: Select all

  @VERSION 5,0
    @APPTITLE "Join Files"
    @APPVERSION "$VER: Hollywood 5.0 (12-March-12)"
    @DISPLAY {Title = "Join Files"}
    @SCREEN {Mode = "ask", Width = 640, Height = 480}

    pattern$ = "jpg|jpeg|bmp|tif|gif|png"

    title$ = "Choose files"

    tempfile$ = "temp.png"

    f$ = FileRequest(title$,pattern$,#REQ_MULTISELECT)

    NPrint("Path:", PathPart(f$[0]))

    NPrint("Files selected:", ListItems(f$) - 1)

    While f$[c] <> ""
       NPrint(FilePart(f$[c]))
       c = c + 1
    Wend

       d = 1 ;  id brush counter

    While f$[e] <> ""
       LoadBrush(d,f$[e])
       ret_val, table = IsPicture(f$[e])
    If ret_val = True
       NPrint("The file is an image? :", ret_val)
       NPrint("Width:", table.Width)
       NPrint("Height:", table.Height)
       NPrint("Alpha:", table.Alpha)
       NPrint("Vector:", table.Vector)
    Else
       NPrint("The file is not an image...")
    EndIf
       d = d + 1 ;counter
       e = e + 1 ;counter
    Wend

    WaitLeftMouse()
    End()
       

Re: How to read width and height parameters from an image?

Posted: Sun Feb 23, 2014 10:47 am
by NubeCheCorre
It works, thank you!, so is it better to use this kind of syntax (table.Value) instead of table[]?

Re: How to read width and height parameters from an image?

Posted: Sun Feb 23, 2014 6:40 pm
by airsoftsoftwair
It's not a matter of syntax, your code was just plain wrong :)

Re: How to read width and height parameters from an image?

Posted: Sun Feb 23, 2014 7:09 pm
by NubeCheCorre
ok, I thought that being "table" a table, I could access to its element using a index, instead i have to use the string as index :)