[ Pobierz całość w formacie PDF ]
.Specifically, thepbmplus utilities giftopnm and pnmtops are used to quickly convertthe GIF to a PostScript file using the same system()function as the coloring iteration.system("giftopnm /tmp/17882.gif| pnmtops > /tmp/17882.ps");Then, similar headers as before are output to the client as soonas the previous process finishes.Content-type: text/htmlLocation: /tmp/17882.psCautionMost likely, your Web daemon is running without any particular environment variables set, including PATH, so it won't know where to find the giftopnm and pnmtogif binaries.You might need to include additional directory path information whencalling these programs.HousekeepingIf many people are using your coloring application, chances arethat the process ID counter will have reset, and you will be dealingwith process ID file names that already exist in your temporarydirectory.But, as mentioned before, you don't want to deletethe files prematurely in case users want to backtrack and modifyprevious iterations.As a solution, you rely on the popularityof the application to clean up after itself.A step not mentioned earlier is that the first time the coloring.plscript is executed and a fresh image is copied, the script alsoscans the temporary directory to check for "old files."In this case, the Perl script looks for files that end in.gifor.ps and that are olderthan approximately 15 minutes and then deletes them.opendir (TEMP, "/tmp/");@tmpfiles = grep(/\.[gp][is][f]?$/, readdir(TEMP));foreach $tmpfile (@tmpfiles) { if ((-M "/tmp/$tmpfile") >.01) { unlink("/tmp/$tmpfile"); }}closedir (TEMP);Final AdviceAs you can see, it's really not difficult to build something spectacularwith the right tools.The actual code to implement the coloringbook is rather trivial.As the World Wide Web evolves even further,it will become even easier to create similar applications.A new Perl 5 module has been released, for example, that dynamicallyaccesses the gd library routines from within the Perl script,eliminating the need for a separate C binary to handle the graphicsprocessing.Also, new technologies such as HotJava are redefiningthe boundaries of interactivity, making such applications as aninteractive coloring book rather unimpressive.The good news is that even though older applications like a coloringbook that uses CGI might be old hat to you and me, there alwayswill be someone new to the Web who will think it is amazing.Figure 31.6: The finished product
[ Pobierz całość w formacie PDF ]