Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Take-Home Exams-Fall 2004

Take Home Exam 2


You have learned a nifty trick. Your browser can make pictures
any size you want using the "height" and/or "width" attributes.
However, there is one slight problem with this approach. Let's
say you have a directory containing 100 really big pictures. You 
want to make a thumbnail page so you use the height/width trick.
But here is the problem. The browser still has to download all the 
great big picture files in order to be able to produce the 
thumbnails. On a relatively slow internet connection this can take
a really long time.

So what to do?

You could write a function that would truly make a smaller version of
your picture. In other words create a true thumbnail. Then the 
browser would only have to download the small thumbnails to give you
an idea of what you had. 

So this is what we're going to do:

You are to write a function (may be more than one if you want) called
thumber. It should be saved in a file called thumber.py

This function will take in a directory (actually a string) and a number.
Let's call this number "maxedge".

Your function will open the directory whose name was passed in and go 
through all the files processing only .jpg files. For each .jpg file
it will make a true thumbnail image. The thumbnail will have the original 
file name with tn_ prepended. The thumbnail will be the same aspect 
ratio (ratio of height to width) as the original image with its maximum 
dimension equal to the number "maxedge" passed in. For example, if the number 
passed in is 100 then a 600 x 450 image would have a 100 x 75 
thumbnail created. If the original were 450 x 600 then the thumbnail 
would be 75 x 100. If the largest dimension is less than or equal to 
100 then no thumbnail needs to be created but a copy of the original 
image can be made and named as per above (i.e. tn_originalname.jpg).
Note: Simply round numbers to whole numbers if they are fractional.

At the same time your function should be creating a web page which will
display the thumbnails each of which will be linked to its parent image.
That is if you were to be viewing this web page and click on a thumbnail 
the large image would be displayed.

Note: If the largest dimension of one of the pictures is less than "maxedge"
just make a copy of the image as the thumbnail.

Also note that when you are testing your code it's a good idea to remove all of the thumbnails that the program creates (by hand) or
you will start making thumbnails of thumbnails!


To help you we are including a sample function that would scale an image
by some scale factor:

def scaleImage(picture, scale):
# Produces a new picture "scale" times the size of the picture 
# passed in
  # Get existing picture dimensions
  oldheight = getHeight(picture)
  oldwidth = getWidth(picture)
  # calculate dimensions of new picture
  newheight = int(oldheight * scale)
  newwidth = int(oldwidth * scale)
  # Make the new picture
  newpic = makeEmptyPicture(newwidth, newheight)
  # Go across each x in new picture
  for x in range(1, newwidth+1):
    # Calculate the x in the old picture that 
    # corresponds to the x in the new picture 
    oldx = max(1, int(x/scale))
    # For each x go down all y's in new picture
    for y in range(1, newheight+1):
      # Calculate the y in the old picture that 
      # corresponds to the y in the new picture
      oldy = max(1, int(y/scale))
      # Get the color of the old pixel
      col = getColor(getPixel(picture, oldx, oldy))
      # get the new pixel
      newpix = getPixel(newpic, x, y)
      # And set the new pixel to the old pixel's color
      setColor(newpix, col)
  # Very important: return the picture to the caller
  return newpic



Note: Feel free to modify this function or even write your own. It is provided here just to give an idea of how scaling can be accomplished.


Examples


Note: These examples essentially demonstrate the minimum requirments. Feel free to make your own improvements. For example, you might want to have the browser display the names of the files in addition to the thumbnails. That's perfectly fine.

Here is an example directory:

Uploaded Image: th2directory.jpg

Here is typical html that would be produced:

Uploaded Image: th2html.jpg

Here is the html rendered in a browser

Uploaded Image: th2browser.jpg









This is a NON-COLLABORATIVE ACTIVITY! You may not talk to anyone about their code, nor look at anyone else's code, nor allow anyone to see your code. This is a TAKE HOME EXAM. It is an "open book" exam. You may use your book, any slides, any material in the CoWeb, and any programs you've written (even with others). (I'll bet Homework 2 would be useful for this one...)

Please, PLEASE, PLEASE do NOT get someone to write this program for you, nor get help from anyone. We submitted a lot of academic misconduct cases in the summer, and we will do it this term, too, if need be. We plan to use plagiarism detection software to check the submitted code. Please do the take home exam yourself.

Ask questions on Fall 2004 Take Home Exam 2 Questions Page but be sure to ask questions only about objectives and process. You are welcome to ask questions about any of the programs in the book or in the slides, or any of the topics in the class (e.g., "I don't understand mirroring – can you help me go through it again?") but you cannot ask anyone (even the TA's or teacher) about your own solution. DO NOT POST ANY OF YOUR CODE ONTO THIS PAGE IN ASKING QUESTIONS!

Turn in your program via JES as "exam2". When you turn in your exam, you are to enter into the Comment area the statement: "I did not provide nor receive any aid on this exam." IF YOU CANNOT MAKE THAT STATEMENT TRUTHFULLY, DO NOT SUBMIT YOUR EXAM! ANY EXAM WITHOUT THAT STATEMENT WILL NOT BE GRADED.







Take Home Exam #1:


Below is the base image that you are to manipulate. (You'll need to download this picture and store it in your media directory. Right click on this picture, choose "Save As," then save it in your media directory.) (Keep scrolling down to see the rest of the instructions.)

Uploaded Image: baseimage.jpg

You are to turn it into this:

Uploaded Image: exam1result.jpg

You will do this by:


The original image was 207 x 384.

This is a NON-COLLABORATIVE ACTIVITY! You may not talk to anyone about their code, nor look at anyone else's code, nor allow anyone to see your code. This is a TAKE HOME EXAM. It is an "open book" exam. You may use your book, any slides, any material in the CoWeb, and any programs you've written (even with others). (I'll bet Homework 2 would be useful for this one...)

Please, PLEASE, PLEASE do NOT get someone to write this program for you, nor get help from anyone. We submitted a lot of academic misconduct cases in the summer, and we will do it this term, too, if need be. We plan to use plagiarism detection software to check the submitted code. Please do the take home exam yourself.

Ask questions on Fall 2004 Take Home Exam 1 Questions Page but be sure to ask questions only about objectives and process. You are welcome to ask questions about any of the programs in the book or in the slides, or any of the topics in the class (e.g., "I don't understand mirroring – can you help me go through it again?") but you cannot ask anyone (even the TA's or teacher) about your own solution. DO NOT POST ANY OF YOUR CODE ONTO THIS PAGE IN ASKING QUESTIONS!

Turn in your program via JES as "exam1". When you turn in your exam, you are to enter into the Comment area the statement: "I did not provide nor receive any aid on this exam." IF YOU CANNOT MAKE THAT STATEMENT TRUTHFULLY, DO NOT SUBMIT YOUR EXAM! ANY EXAM WITHOUT THAT STATEMENT WILL NOT BE GRADED.


See Hotspots #2 to see previous Take-Home Exams.

Links to this Page