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.
- The main PHP page: erasingpixels.php
- Introduce the program to the user
- 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
- Display the original picture and the reduced color version (check the HTML of my simplistic solution to see how the other script is called)
- The second PHP page: erasepix.php
This script generates the modified picture.
- Receive the name of the picture and the number of pixel colors from the original to be used in the copy
- 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)
- Sort the frequencies
- Create a new image which is the same size as the original
- Allocate the number of colors requested using imagecolorallocate(), plus one to be used for the "background" where pixels are not having their colors set
- 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
- The solution provided does NOT have much information about the program and its use. Yours must have more.
- Use popen() as suggested in the Processing Sports Information Problem to determine the names of the pictures in your images/ for use in the select tag. This allows you to add more pictures to the directory without having to alter your code.
- As an extra, you may allow the user to specify a picture from the Internet.
- If you are interested in manipulating graphic images, you may decide to allow the user to modify the picture in other ways.
© 2008 DFStermole
Created 14 Dec 08
Last Modified 16 Dec 08