RENDERMAN 22 DOCUMENTATION

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

IceMan

Please refer to the "it" - IceMan documentation page.

"it" Application

...

 

Tip

You can use the Save Session... and Restore Session... functions here to help you get a catalog set up quickly.

Web Bling
Anchor
webscipt
webscipt

What say we trick out our little Web page? Let's make a dazzling four column table with thumbnail images of the contents. This will demonstrate how to perform some basic image processing, including resizing the images in our catalog and saving the thumbnails to disk.

To create the thumbnail images we use the handy Reformat operator. Reformat can change and/or resize an image in many different ways, depending on how you want to crop or squeeze your images into the new shape. For the Web page we want to create uniform-sized images that are letterboxed if they are not the right shape. In Reformat terminology that means "preserve aspect ratio and don't crop".

Tip

As it happens, "it" images can be annotated. Go to Window > Inspector and to the right of the image window, you should a large text box for you to add notes. When you save a session the notes get saved along with it. Before you run the example, add notes to a few of the images in your catalog to see how that will come out.

When you run the script this time you'll see that a directory called thumbs is created alongside the html file, and in the small jpeg versions of the images are saved therein. You'll also see in the "it" Catalog window that the Catalog now has a new image for each thumbnail that was made. You can delete them if you like.

Here's the updated script:

Code Block
import it
import ice

it.app.Info('Defining Web Page Extension')

def makeWebPage2 (filename):
    f = open(filename, 'w')

    topDir = it.os.path.dirname(filename)
    thumbDir = topDir + '/thumbs'

    if it.os.path.lexists(thumbDir) is False:
        it.os.mkdir(thumbDir)

    f.write('<html>\n')
    f.write('<table cellspacing="10" align="center>\n')

    cat = it.app.GetCurrentCatalog()

    col = 0

    for i in range(0, cat.GetChildCount()):
        child = cat.GetChild(i)

        if col == 0:
            f.write('<tr>\n')

        f.write('<td valign="top">\n')

        name = it.os.path.basename( child.GetFilename() )
        h = it.os.path.basename( child.GetLabel() )
        thumbFile = thumbDir + '/' + h + '.jpg'

        thumbIceImage = child.GetImage()
        reformat = thumbIceImage.Reformat([0,200,0,200], True, False)
        reformat.Save( thumbFile, ice.constants.FMT_JPEG)

        f.write('<img src="thumbs/%s.jpg" alt="%s">\n' % (h, name))
        f.write('<br><b>%s</b>' % (name))

        notes = child.GetNotes()
        if notes != '':
            f.write('<small><pre>\n%s</pre></small>\n' % (notes))

        f.write('</td>\n')

        col = col + 1
        if col >= 4:
            f.write('</tr>\n')
            col = 0

    if col != 0:
        f.write('</tr>\n')

    f.write('</table>\n')
    f.write('</html>\n')

    f.close()

 

Replace the original script with the script above, save the file, and execute as you did before. This time you'll get a slightly nicer looking page with thumbnails, notes, and labels.

Here is some more information about developing scripts