Assignment Solutions Request using PHP's GD Library

Background Information

Several CS courses post solutions online with the student's Quest ID as a watermark. This page describes a PHP script that provides such a feature. The script uses PHP's GD image library. Students will see the solutions as a PNG image file. Sample output (shrunken):

Sample Output

There is another set of scripts (AssignmentSolutionPHPScript) which also adds watermarks. Those scripts use PHP too, but the image processing is done with a bash script and ImageMagick.

Setting Up the Script

If your course has never used this script before:

Download the file WatermarkSolutions.zip at the bottom of this page, and save it somewhere on the course account. In a terminal, cd to where you saved it, and run:

unzip WatermarkSolutions.zip
cd WatermarkSolutions
bash Install.sh

Now, open /u/csXXX/public_html/SolnsWatermark/generateWatermark.php and edit the $staff array to include the term's ISC, tutors, and instructors.

You can now open a Web browser and try going to these URLs. Use your actual course instead of csXXX.

https://www.student.cs.uwaterloo.ca/~csXXX/SolnsWatermark/generateWatermark.php?assn=demosolns1
https://www.student.cs.uwaterloo.ca/~csXXX/SolnsWatermark/generateWatermark.php?assn=demosolns2
https://www.student.cs.uwaterloo.ca/~csXXX/SolnsWatermark/generateWatermark.php?assn=demosolns3

You should see some sample code with your Quest ID as a watermark.

You can now edit requestAssnSoln.php. That file contains PHP, but it's mostly just HTML. It displays links to the solution files. Edit it so that it fits nicely with your course website's design.

Do this at the start of every term:

  1. Open /u/csXXX/public_html/SolnsWatermark/generateWatermark.php
  2. Edit the $staff array to include the term's ISC, tutors, and instructors.

What To Do For Each Assignment

Obviously, wait until after the assignment is due before posting solutions.

Step 1: Convert the solutions to a PNG image file

If the solutions are in plain text, first convert it to a PDF. This can be done by printing the solutions to a PDF file. Then, convert the PDF to a PNG image file.

Method 1: Use an image editor

Open the PDF file in an image editor like Photoshop or Gimp. Then save the file as a PNG.

Method 2: Use ImageMagick's convert command

In a terminal, navigate to the directory containing your PDF file. Then use a command like:
convert PDF-to-convert.pdf -flatten -trim Output-picture.png

Notes:

  • The resulting PNG image should be at least 720 pixels wide and 720 pixels tall. If it isn't, resize it with an image editor.
  • Don't make the image too long, either. If it's getting really long, break the assignment up by question.
  • The image should be legible. Don't use a font that's too small.

After you have the solutions in a PNG file, move it to /u/csXXX/SolutionsRequest/filename.png. Choose any filename you like.

Step 2: Release Solution and Add Link

Open /u/csXXX/public_html/SolnsWatermark/generateWatermark.php and add an entry to the $solution_files array. Use any key you like. For the associated value, put the path to your PNG file.

Add a link in requestAssnSoln.php. The link should point to generateWatermark.php?assn=ASSNID, where ASSNID is the key you used in generateWatermark.php.

Try viewing the solutions to make sure it looks good. If the watermark is not transparent, open your PNG file in an image editor and re-save it.

Who can view solutions?

Only these people can view solutions:

  • Students listed in /u/csXXX/.classlist
  • Students listed in /u/csXXX/.exceptions
    You can manually grant access for specific students by putting them in this file. Each line in .exceptions should have this form:
    studentIDno:QuestID
    Please don't add any spaces or tabs at the end. Example line: 20401835:j9smith
  • Staff listed in the $staff array in generateWatermark.php
    Staff can add a u variable at the end of the URL to change the watermark text. For example:
    https://www.student.cs.uwaterloo.ca/~csXXX/SolnsWatermark/generateWatermark.php?assn=a00q1&u=whatever

Log File

A log entry is made every time someone successfully views a solution. The log file is /u/csXXX/course/SolutionsRequestLog.txt. Each entry has the format:

Time, Watermark Text, Quest ID, assignment ID

Topic attachments
I Attachment History Action Size Date Who Comment
Compressed Zip archivezip WatermarkSolutions.zip r3 r2 r1 manage 603.3 K 2011-12-19 - 22:38 YiLee All the files you need and more!
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2011-12-19 - YiLee
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback