Archive for January, 2006

How to Make Pretty Entry Number Graphics

Sunday, January 8th, 2006

You may have noticed that in my latest revision of my blog template that I added a nice little blue image for each entry’s number that also acts as a permalink to the main entry page. In the older version of the template, the entry number (which is not the same as the entry ID because some draft entries have been deleted over the years) was a simple link that was fairly hard-to-find and, because of its smallness, also difficult to click on. I focused on improving this in my last round of updates to the template, deciding that a larger graphic would be easier to click while still aesthetically pleasing. However, making an image myself for every entry number (the first 228 and the hundreds in the future) was not something I wanted to do, so I worked some PHP magic to automate the process. Read on to find out how I accomplished this. This entry will be fairly technical, so you might want to skip it if you don’t understand HTML and CSS.

First, here is the code in the Langosta template that generates the HTML for the image:

Editor’s Note: Code snippets have been removed due to some corruption while moving between blogging systems. Sorry!

This is part of the template code that executes within a five-entry loop on the main blog page. For each entry, there is an Entry object stored in a temporary $entry variable that allows the programmer to access data related to the entry via its properties (ex: the entry title is stored in $entry->entry_title). Rather than try to explain further the specific HTML and PHP, I’ll just give a summary of what this code/markup is doing. It:

  1. Makes a permalink to the entry using its name and puts the title of the entry in the link’s tool-tip.
  2. Creates a span element (a versatile HTML element that has no real purpose except to be changable with CSS) classed as a “number” within the link.
  3. Within the span element, places another span element called “number-sign” next to the entry’s number.

I know this seems a bit complex for something as simple as showing a number, but you’ll see my reasoning soon enough, if you haven’t already. Now, have a look at the CSS that makes this HTML pretty.

Editor’s Note: Code snippets have been removed due to some corruption while moving between blogging systems. Sorry!

This code does the following things:

  1. Floats the graphic to the left
  2. Changes the span from display: inline to display: block, meaning that it will acquire height and dimension like a box or paragraph rather than just a link.
  3. Sets the dimensions and margins of the graphic
  4. Sets the text-indent property to “-5000em” so that only the actual graphic is shown and not the number in the HTML - this is so that a user with CSS and images turned off can still see an entry number

I skipped over a couple of things in the above explanations that I will now cover. In the first code block the span element that has the class “number” also has a style attribute which is set to a background image. If you look closely, you’ll see that this background image is special because it isn’t really an image at all - it’s a PHP file with the following lines of code in it:

Editor’s Note: Code snippets have been removed due to some corruption while moving between blogging systems. Sorry!

This script fools the web browser into thinking it is an image by first setting its Content-Type header to “image/png” (meaning a PNG image). The script then figures out what number it should display from the HTTP $_GET variable that PHP provides. Before actually creating the graphic, the script checks a directory on my website that contains every graphic it has ever created in order to see if it needs to do all the work of creating a new one. If it has already created a graphic for this entry number, it simply loads that one. If not, it proceeds to make the new graphic.

Generating dynamic images in PHP is simple because of a bundled library called GD. The script uses a GD function, imagecreatefrompng to load a base entry number graphic that is the correct size and already contains a number sign and the rounded blue background. Then, another GD function, imagecolorallocate is used to tell GD that I want to use a color with the RGB values 234, 234, and 234 (a light shade of gray) for the entry number. Finally, the imagettftext GD function is used to add the number to the base graphic at a specific position (see the PHP manual for how the positioning works - it’s weird) using the color that I created earlier and a font on my server (Lucida Grande Bold). The final steps are to place the newly created graphic in the directory full of other graphics, output the image to the browser, and destroy the graphic to save memory on the server.

So why exactly is all this work necessary just to display a simple graphic? First, because I wanted to make my actual entries look as much as possible like the mockup I created in Photoshop, and this was one of the elements of that mockup. In the mockup, the entry number was well-rendered, anti-aliased text with a pleasant blue background, not the crappy, jagged text that a large number of people see on their screen. By using this method, I gained complete control over what the graphic looks like and without forcing users to turn on ClearType or use a Mac in order to see it as Photoshop might render the text. And I just didn’t want to create hundreds of little graphics, a task that could have taken hours (and more time after posting each entry), when my PHP script only took a few minutes to whip up and debug.

Hopefully you got something out of this entry - I plan on trying to write more about programming this year, if I can. I know certain readers don’t care for my more technology-orientated writing, and that’s okay - they’ll just have to put up with entries like this one every once in a while.

My Academic Future

Tuesday, January 3rd, 2006

I am frustrated. I know that my constant wailings probably get old sometimes, but if I ever have anything more optimistic to write about, I’ll post about it immediately. Anyway…I am beginning to fear that school is pushing me to the breaking point. Many times in the past I have written about particular weeks or days when things seemed bleak and the assignments kept pouring in, with new ones coming faster than I could finish current ones. In those entries I included my usual melodrama, likening school to slavery and teachers to Nazis. But this time is different.

Long ago, I lost my passion for academia. That probably happened sometime last year, but I replaced it with programming and debate and other things. My friends and certain classes, like my beloved seventh-hour Spanish period with Sra. Nasr, were what kept me going through the school day. But now, I feel that I have lost everything that once made me happy to go to school.

Let’s go through a typical day. In the morning, I wake up at about 6:30, get ready for school, and catch a bus without eating breakfast. I arrive at school around 7:05, so I work on homework that I didn’t have time for the night before until 7:20, when the last bell rings. In my first class, English, some days are good, others aren’t. Lately, things have been better now that my classmates notice and respect me, and it seems to fly by. Homework in that class is usually about 30 minutes to two hours per night, depending on the assignment.

My next class is newspaper, in which I spend most of the 45-minute period laying out our next issue on a computer using Adobe InDesign. Back when I was still figuring out how the program worked, there was some fun in it, but lately it has become more and more mundane. Sometimes I just stop working and read articles for most of the period (some of them are really good for a school paper). Near the end of the period I usually make some dumb excuse for my teacher about why I don’t have my required article written yet and why that basketball team website still hasn’t come together. I feel guilty about it, but I don’t know what else to do.

My third period class might be the highlight of my day: IB History of the Americas. The subject matter isn’t exactly exciting, but I absorb it like a sponge and I excel at spewing it back out in essays and on tests. The teacher, Mr. O’Leary, is a great guy who spends more time on some days just talking with us than he does teaching (yet we are somehow still on track with the IB schedule). The only thing I don’t like about the class is that, compared to AP European History, it feels easy. DBQs have no requirements other than that the student must answer the prompt completely and use all the documents - there is nothing about grouping documents together and analyzing points of view like there was with AP Euro. The same goes for FRQs, which basically are just giant listings of facts. I usually do them in my native essay format, but even an outline is acceptable as long as it covers all the information. The other students seem to love that class because, though it is a core IB course like English, kids who regularly get Cs on their English essays (and there is a fair number) almost always get As on their HotA assessments. So far, I think the lowest grade I’ve ever received on a history assessment (test, project, or essay) was a 98%, and yet no one seems to care that I’ve hit a performance ceiling and am left with nowhere else to go but the boring world of doodles and paper airplanes.

My fourth class of the day, Spanish, is fast becoming a major problem for me. I finished my sophomore year having completed Spanish IV Honors, the same course that many advanced seniors take. While that class was no Spanish 5-6 with Nasr (the numbering is different in Arizona, 5-6 is like III), it was a full 90 minutes, allowing for lots of time for me to really feel absorbed in the language. Now, with a paltry 45 minutes, I barely get anything out of it. Not only is my current class short, but it is basically a repeat of what I have already learned, with most of the content being at about the level of Spanish III. THREE! That is a full two years of Spanish in Arizona. Here, it might be one year because of block scheduling, but still! I can barely stand it anymore! My assessments are almost always perfect, with my only weak points being when I try to speak the language. I think this has to do with the fact that I try to use what I learned in prior years without knowing for sure if I still am getting it right, so I stutter and stumble over my words and mispronounce things. Languages, whether they be spoken and written or programmed, are something that I was once passionate about learning. With Spanish, I fear that I have regressed so far that it could be the end of this school year before I am back to the level that I was at last year. It’s just wrong.

Before I move on to my other classes, I have an important point to make about the difference between education in Arizona and education in Wisconsin. In Arizona, everyone knows that the system is flawed. The students and parents know it, the teachers certainly know it, and most of the administrative staff know it. Even in schools like CSHS that were considered to be “exceeding the standard,” the quality of the education being delivered in most subjects is subpar compared to leading states like Wisconsin or Minnesota. In the same token, Wisconsin’s educators know that their system works, that it has been proven to turn out more students that meet national standards for their grade level and that do well on standardized tests than almost every other state’s education system. But being on top can have adverse side effects.

In Arizona, the knowledge that educators need to to better across the board stimulates some standout teachers and staff members to go above and beyond. In my case, my freshman English teacher offered to give me individual instruction to challenge me further. One of the vice principals, after seeing the kind of difference I was making in my work on the school website, offered me a deal where I would spend my English period working on the website as long as I continued to work individually and get my assignments in on time. Later, she allowed me to work more on the site over the summer and work on Mr. Trapani’s computer network at the same time - for honors credit. And not just one honors credit - four honors credits. In the first semester of my sophomore year, I became the sole maintainer of the website and was given even more time in my day to work on it. Mr. Trapani supported me by giving me a computer in his lab and advice when I needed it, even though web design is far from his field of expertise. Sometime in October of that year, we began having semi-regular board meetings where the librarian (my supervisor, technically), Mr. Trapani, one of the IT people, that wonderful vice principal, and sometimes the principal herself, would sit in. I was amazed, floored, even. I was doing this job as if I were an adult working for a small company, and I, a fifteen-year-old kid, had gained the respect of people twice my age because of my skills and intelligence. My point here is that not just one teacher, but about a half-dozen people at my school, adults with much more knowledge and wisdom than I had, were willing to recognize that I was no ordinary student and do something to challenge me further. Even after I had moved, my AP Euro teacher continued to work with me for another semester so that I could still get my five on the test in May. Though they did not always succeed with some students, these educators would go the extra mile when they found a student willing to come along with them.

Something like this would never happen in Wisconsin, or at least not at a school like OHS. Here, teachers and administrators either believe so strongly in their system or are so bound by it that they can do nothing when the system fails. Sure, about 95% of the students at OHS seem to be happy with their classes and are performing reasonably well, or at least better than they would have in another district or state. But what of the 2.5% who fall to the bottom and the other 2.5% at the very top? At first glance, it would appear that the IB Programme, the most challenging of all the advanced college preparatory programs, is the solution for those at the top. But while it works for most of them, what about students like me? Students who are, at least in a few of their classes, finding it difficult or impossible to improve further? Maybe the problem is that there are no other students like me. I find that hard to believe, but so far, in all of my classes, there are only a select few that come close (I say this truthfully, without meaning to sound arrogant), and there aren’t many who have grades like mine in every single class.

I’ve written before about my attempts to challenge myself. I tried in my first semester in Wisconsin to get into at least one computer-oriented class. But no, my schedule was too taken up by prerequisites and Algebra II Honors, half of which was basically the same thing as what I had already covered in Honors Algebra 3-4 at CSHS (again, the numbering thing is weird). The only class that entire semester that challenged me was not even one that I was taking in school - it was AP Euro, which accounted for at least half of all my homework. But I was buoyed by the promise of IB on the horizon, and I imagined that I would finally go to school and feel as if I was getting some value out of it.

I tried other things too - I talked to my counselor and my dad about Algebra II, but it was decided that I should stay in the class because I would otherwise not be prepared for Pre-Calculus this year. I think my counselor failed to understand that I could have studied the Algebra II textbook over the summer and been more than prepared for pre-calc, but I was a student and he an administrator - to give me any trust or advantage would disadvantage other students. That was never said aloud, but it was what I gleaned from observation. It happened again when I talked to one of the main tech support people about possibly working on the school’s computers or website. There was this “you’re just a kid who doesn’t know his place, now get back in line with the rest of the sheep” kind of mentality, veiled in politeness. At this point, with my schedule set by the IB gods, I won’t attend a single technology class in my entire high school career. I am doomed to gain new knowledge on my own, even though I don’t know where to begin and am always being reminded that, even though I have a good grasp of web development, there is a vast world of technology out there that I don’t understand in the slightest. I think that I am reaching a point where I need someone to guide me, a mentor, if not an actual teacher, someone who can stay one step ahead of me and help me when I get stuck. But even if someone were willing to do that, the fact would remain that I have absolutely no time at all in my day to program or tinker or explore anymore.

And getting back to that busy day, my final two classes are physics and pre-calc, the two that I like the least yet spend the most time in because they are full, 90-minute blocks. Physics is always confusing, and I often find myself teetering on the edge of a B+, yet I know that I could do better if I had more time to study the textbook and actually do the homework problems that are assigned. Pre-Calculus is better, even though our textbook is one of the worst I’ve ever used. In Algebra II, I would often simply ignore the teacher and read the section in the book, teaching myself the concepts and doing the homework in class so that I would have less at home. I haven’t taken notes in math since freshman year. But now, with such a sucky book, it takes a lot longer for me to understand things that way, even though I prefer it. It doesn’t help that I often do my math homework during lunch because I don’t have time at night.

Once I finish school, I spend my activity period (a half-hour at the end of the day between the end of classes and the time that the afternoon buses arrive) either working on the newspaper with the other design editors that aren’t in my class or in the writing center, a kind of writer’s workshop where students can come voluntarily (unless their teachers force them to come) to get help with their writing. After that, on Mondays, Tuesdays, and Thursdays, I have driver’s ed. Yes, I still don’t have my license yet. Something about being racked with depression didn’t exactly make me excited about it last year. I do have my permit, though, which I guess is better than nothing. Anyway, driver’s ed sucks. Right now, all we do is sit in class for two hours each day and talk about various common-sense concepts such as slowing down in a snowstorm. I would hate it less if it wasn’t extending my school day by about three hours. Luckily, the classes end on Thursday, and that huge chunk of time will come flooding back. I can’t express in words how much I am looking forward to that. However, before that happy day, I have to finish my “project” (a website, of course) and present it somehow to the class. It was due before Christmas break, but I’ve always had better things to do, so now mine probably won’t be in until Thursday.

Then, I get home at 6:15 or so, spend the next 45 minutes eating dinner and relaxing (finally!), take a shower sometime between 7:00 and 8:00, spend an hour reading blogs and other websites, and finally, at 9:00, begin my homework. Sometimes it’s two or three in the morning before I’m done. Tonight, because I chose to not be as antisocial as usual and post on my blog, it will be even later. I’ve gotten used to not sleeping though…I simply go to bed a bit earlier each night of the week, sometimes only by a half an hour, and then by Friday I feel that I have improved by going to bed “early” at midnight-thirty the night before.

It’s time for me to stop now and finish my aforementioned homework, but I don’t want to. The frustration and depression and lack of sleep and feelings of having my talents wasted are about enough to make me scream, “Fuck it all!” and give into the desire to burn out, slowly and shamefully. Then I’ll grow my hair out and find a guitar and sing grungily to the world about how everything sucks.

Sorry, that was a bit pessimistic, even for me….