Next / Previous / Contents / TCC Help System / NM Tech homepage

12.9. FormPhotoSet._addSize(): Add the size cell

This method generates the second column of the table, displaying the image size. See Section 4.3, “XHTML for the form page”.

# - - -   F o r m P h o t o S e t . _ _ a d d S i z e

    def _addSize(self, tr, archImage):
        '''Generate the image size cell of the table.

          [ (tr is an et.Element) and
            (archImage is an archx.ArchImage) ->
              tr  :=  tr with a new td added containing size data
                      from archImage ]
        #-- 1
        # [ tr  :=  tr with a new td element added
        #   td  : = that new td element ]
        td = subElement(tr,, VALIGN_TOP))

The three lines in this cell are vertically stacked by placing each inside a div element.

The frame area appears only for images that have a scan attribute that tells the dots per inch of the scanner. If this attribute is missing, the original is from a digital camera, and we don't display the frame area at all.

To calculate the percentage frame area, we need to know the area in square millimeters of a full frame. Then we use the scanner precision, expressed in pixels per millimeter, plus the size of the image in pixels, to calculate the fraction of the frame. Here is the math:

  1. The constant FULL_FRAME_MM2 gives the area of a full frame in square millimeters: 24mm × 36mm for a 35mm film frame.

  2. Since 1 inch = 25.4mm, we can convert that value to square inches by dividing by the square of 25.4.

  3. To convert square inches to pixels, we multiply by the square of Pi, the dot pitch of the scanner in dots per inch. This gives us Pf, the number of pixels in a full frame at resolution Pi, which is available as archImage.original.scan.

For an image with x pixels, the image size as a percentage of the frame, then, is 100 × x / Pf.

        #-- 2
        # [ if archImage has a known dots/inch ->
        #     td  :=  td with a div element added, containing the
        #             percentage of a full frame covered by archImage ]
        if  archImage.original.scan:
            fullFramePixels  = (FULL_FRAME_MM2 / (MM_PER_IN**2) *
            thisFramePixels = archImage.wide * archImage.high
            framePercent = 100.0 * thisFramePixels / fullFramePixels

The width and height are added in separate div elements; the latter is preceded by “x”. It would be nice to have the special Unicode character “×” (code point 0x00d7), but so far I haven't been able to figure out how to make it work.

        #-- 3
        # [ td  :=  td with two divs added, the first containing
        #           the image width from archImage, the second
        #           containing 'x' and the image height ]
        td.append(E.div(TIMES, str(archImage.high)))