Back to DFS's Workshop Page
Back to Agenda Page


Processing Graphics Information Problem

Erasing Pixels from a Picture

There are many programs which enable you to manipulate photographs. This small project will give you an opportunity to start learning to program alterations to pictures. You will take a user-specified picture and create a copy which consists of only the user-specified number of most frequently used colors.

You will create two PHP scripts, the first of which calls itself recursively, allowing the user to choose the picture and the number of pixels to be used. The second script is called from the first to generate the reduced color picture.

  1. The main PHP page: erasingpixels.php
    1. Introduce the program to the user
    2. Give the user a list of pictures that can be used, making sure that the user does not have to reselect the picture each time as he experiments with the number of colors to be used
    3. Display the original picture and the reduced color version (check the HTML of my simplistic solution to see how the other script is called)
  2. The second PHP page: erasepix.php
    This script generates the modified picture.
    1. Receive the name of the picture and the number of pixel colors from the original to be used in the copy
    2. After determining the dimensions of the picture, do a tally of the frequencies of occurrence of the pixel colors (you may find it convenient to use non-numeric, non-sequential subscripts for your tally array: click here)
    3. Sort the frequencies
    4. Create a new image which is the same size as the original
    5. Allocate the number of colors requested using imagecolorallocate(), plus one to be used for the "background" where pixels are not having their colors set
    6. For each pixel whose color is in the list, set the corresponding pixel in the reduced color version using imagesetpixel()

Click here to see a solution to this problem.

Click here to see a solution for a "negative version" of this problem.

Notes


© 2008 DFStermole
Created 14 Dec 08
Last Modified 16 Dec 08