How to read width and height parameters from an image?

Find quick help here to get you started with Hollywood
Post Reply
User avatar
NubeCheCorre
Posts: 56
Joined: Mon Mar 19, 2012 1:24 am
Contact:

How to read width and height parameters from an image?

Post by NubeCheCorre » Fri Feb 21, 2014 10:36 pm

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 :)

PEB
Posts: 262
Joined: Sun Feb 21, 2010 1:28 am

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

Post by PEB » Sat Feb 22, 2014 4:29 am

The table returned by IsPicture() should do what you want.

User avatar
NubeCheCorre
Posts: 56
Joined: Mon Mar 19, 2012 1:24 am
Contact:

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

Post by NubeCheCorre » Sat Feb 22, 2014 11:19 am

Thank You!! I totally missed that function! thanks! :)

User avatar
NubeCheCorre
Posts: 56
Joined: Mon Mar 19, 2012 1:24 am
Contact:

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

Post by NubeCheCorre » Sat Feb 22, 2014 8:40 pm

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!

patizak
Posts: 1
Joined: Sun May 02, 2010 8:16 pm

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

Post by patizak » Sun Feb 23, 2014 10:10 am

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()
       

User avatar
NubeCheCorre
Posts: 56
Joined: Mon Mar 19, 2012 1:24 am
Contact:

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

Post by NubeCheCorre » Sun Feb 23, 2014 10:47 am

It works, thank you!, so is it better to use this kind of syntax (table.Value) instead of table[]?

User avatar
airsoftsoftwair
Posts: 3206
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

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

Post by airsoftsoftwair » Sun Feb 23, 2014 6:40 pm

It's not a matter of syntax, your code was just plain wrong :)

User avatar
NubeCheCorre
Posts: 56
Joined: Mon Mar 19, 2012 1:24 am
Contact:

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

Post by NubeCheCorre » Sun Feb 23, 2014 7:09 pm

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 :)

Post Reply