PreviousNext…

Fixing stuff

See, this is why it’s cool to run a site like this. You post some code, and a second pair of eyes improves it or fixes it!

Big belated thanks go to Jörg Weske for coming up with a solution to an issue some of you may have already noticed with the Lotusscript version of ImageInfo on this site. This routine allows you to attach image files to a document, extracting colour depth and image dimension data from that file. I use it in the back-end for this very site, and every now and again noticed that the image dimensions were coming through incorrectly (especially for PNG-format pictures).

Being lazy I didn’t get around to investigating. However, Jörg Weske was kind enough to track down the bug in the system and share it with me. Over to Jörg:

I noticed that the function would not always return the correct height and width for a given image. After quite some time with the debugger, I think I identified the — admittedly rather obscure — source for the problem:

Inside the function getImageProps, when reading the binary image data into the array varBinaryBuffer, you are using the LotusScript function InputB. This function will return the binary data as a string which has then to be converted back to bytes. This is where the problem lies…

Great debugging from Jörg! It turns out that the Asc function acting on the InputB data returns the locale-sensitive ASCII character code for the first char in a string. When one feeds the Asc function with characters from InputB they don’t always correspond to the binary value of the actual file data. Jörg came up with an idea for a fix (in ND6 anyway) by declaring a new Byte variable and then doing something like this:

  Get #intFile, , readbyte
  varBinaryBuffer(intIndex) = readbyte

… instead of this:

  varBinaryBuffer(intIndex) = Asc(Inputb(1, intFile))

Jörg goes on to say “Note that this assumes the file-pointer is at the start of the file when calling ‘Get’ for the first time.” So, big thanks to my alert reader, and hopefully this will be of use to others out there.

Update: actually the solution seems to be even easier: I replaced the call to the Asc function with one to Uni which doesn’t appear to have the locale issue. Testing so far is coming up trumps. I’ve updated the code attachment in the article.

Comments on this post are now closed.

About

I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.

";