ImageDimensions

In an image database the .CurrentRecord procedure calculates the height and width of each linked image. It works perfectly nearly all of the time.

fgImage  = ImagePath+Image
fgHigh = h(imagedimensions(unixpath(fgImage)))
fgWide = v(imagedimensions(unixpath(fgImage)))

Using a variation as a formula in a TextDisplayObject, it works to build an array of a selected set:

 FileGlobal fgSizes
 fgSizes  = ArraySelectedBuild(¶,"",
{“howwide = "”+str(h(imagedimensions(unixpath(ImagePath+Image))))+“px"”+¶+“howhi = "”+str(v(imagedimensions(unixpath(ImagePath+Image))))+“px;”})

But when I use it in a procedure, it always yields zeros:

FileGlobal fgSizes
ArraySelectedBuild fgSizes,¶,"",“howwide = "”+str(h(imagedimensions(unixpath(ImagePath+Image))))+“px"”+¶+“
howhi = "”+str(v(imagedimensions(unixpath(ImagePath+Image))))+“px"”

And then it stops working in all uses. Everything comes up zero until I Quit and relaunch the program.

Both arrays above are working with the same 7 records so the number of images shouldn’t be the issue.

It appears that ArrayBuild( will work for me within my procedure, but I’m wondering what could be happening to blow out the ability to calculate imagedimensions in the ArrayBuild? I’d like to understand and know how to avoid the zero scenario.

The imagedimensions( function uses the imageinfo( function to get the information about the image.

The imageinfo( function uses the shellscript( function to run the sips command line program. I haven’t tested it, but maybe shellscript( doesn’t work inside an arraybuild statement.

I would suggest trying using arraybuild( to make an array of paths, then use the looparray statement to calculate the dimensions. In this case I don’t think it will be significantly slower than using just arraybuild, because the real delay will be in executing the shell script over and over. Also, I would suggest only running imagedimensions once per file, saving that to a variable, then extracting v and h from that. Since imagedimensions( causes a shell script to run, it’s kind of relatively slow, so better not to run it twice when not necessary.

Got it. Thanks!

Here is an alternative that uses only one shellscript to get the dimensions of all the selected images. Using arrayselectedbuild( with the shellscript batches all the image paths together and returns a list of all the dimensions of the included files. The following arrayfilter( removes the included path and file name from each return and the rest of the daisy-chained functions reformat the output to match what you have in your example code.

fileglobal fgSizes
shellscript ||| sips -g pixelHeight -g pixelWidth $1 |||+
    arrayselectedbuild(" ","",{posixpath(ImagePath+Image)}), fgSizes
message arraystrip(replacemultiple(arrayfilter(fgSizes,¶,
    {?(import() beginswith "/","",import()+"pix")}),
    "pixelHeight:,pixelWidth:","howhi =,howwide =",","),¶)

I tested this on a database with only a few image paths so I don’t know how fast it would function for what you have compared to what you are now doing.

Holy Cow, Gary! Who wired your brain anyway?

I do have it working adequately per my process above. Yours might actually be faster but in practice there’s more to the array I’m building than just the sizes. My procedure collects a bunch of info about each of the selected images and builds a ready-to-use HTML page around them.

I appreciate and admire your effort nonetheless.

A guy named Bob.

Would that be ‘Bob Wire’? :wink:

You must be thinking of his wife Barb.

Thorny couple, but sharp.