Conservatives poster
NOW DONE! Go see it.
Utility to make mockups of the Conservatives "are you thinking what we're thinking" poster.
Three processes:
- Front end
- Back end
- Reaper
Front end
frontpage.php:
Web app (PHP). Displays a form to enter text to go on the poster. Form is an invisible textarea over the top of the Conservatives poster, so you can type the text in directly. On submit:
- Get the next number (read and write a number file with locking, so you lock the file for writing, open it, read the number therein (say, 5), increment the number by 1 to 6, write 6 back into the file, and remove the lock)
- Dump text into a file queue/<number>
- Redirect to waitpage.php?image=<number>
waitpage.php:
- Escape number from URL
- if images/<number>.png exists then forward to displaypage.php?image=<number>
- display "please wait": meta refresh, 5 seconds, to waitpage.php?image=<number>
displaypage.php:
- Escape number from URL
- Display image (images/<number>.php)
- Warning: this image will only remain here for half an hour
Back end
Constantly running daemon. On daemon start:
- Load all local ttf files into ImageFont objects and put them in a list
- Load blank poster image into Image object
Daemon main loop:
- If queue/ is empty, sleep 5, loop
- If queue/ is not empty:
- Get oldest file name
- Open it, read text
- Choose a random font from font list
- Write text onto image in font (this bit is tricky; need right spacing, carriage returns, etc)
- Save image as images/<filename>.png
- Delete queue/filename
- sleep 2
Reaper
Every half an hour (run from cron) delete all files in images/ that are older than half an hour.