I ( Macphisto/001011110 ) wrote:
Jon, huh? You're the one that coded the Perl program for the Tux Poster using the Kernel. I don't want any of your trade secrets, but I'm just curious as to how you did that. Did you make the text of the kernel opaque and then overlay them on the image or some other way? Either way, very very cool script.Jon replied:
Regards
Scott A Runnels
As for the Tux poster, I'm guilty as charged on that one. We'll be releasing it under the GPL soon anyway, so there's no reason I can't briefly explain how it works...The rest is mixed banter...I'll note where needed...
Basically, the image is read in, dimensions are gathered and used to determine how many characters can be fit vertically and horizontally while keeping the same aspect ratio of the original image. Given the page size and those characters/line counts, the font size is determined. Then the script just loops through each line, pixel by pixel. If the pixel is transparent, it skips it. If it isn't, the color of the pixel is figured out and the next character in the source text file is positioned and colored on the page. All of this is done with basic PostScript commands. Once the end of the image is reached, the PostScript commands are all written out to an ASCII file which can then be read/parsed by anything that understands PostScript (like ghostview, Acrobat, Illustrator, etc.). That makes the resulting "image" fully scalable and portable between any platform and dozens of programs, so you could plaster the side of a building with it and it would still look good.
Anyway, I'm babbling. ;)
Take care!
Jon
Hmmm, questions questions....Jon:
First: How did you figure out the color of the pixel? Can you do that in PERL ( I've only been programming in PERL for about a year now and I haven't come across anything like it ) or is it Postscript?
To actually read in the image and get dimensions, pixel data, etc., I use the Image::Magick library which you can get from CPAN. It makes image manipulation _very_ easy. You'll need to install the ImageMagick libraries (which are in C, and are relatively likely to already be on your system), and then Image::Magick (aka PerlMagick), which is the actual Perl interface to ImageMagick.Scott:
But getting the RGB value (which is needed for PostScript) can sometimes be a little tricky. Some images store their colors as RGB values, which makes it easy. But others store them as Hex triplets (i.e. "FFFFFF" for white), which isn't too tough, you just have to catch those and run hex() on each part of the triplet. And yet others use X11 color names (i.e. "white", "navajo white", "grey40", etc... look in /usr/X11R6/lib/X11/rgb.txt for the complete list). The X11 color named ones are the annoying ones, but luckily all the RGB values for each color name are in that same file.
Second: What's the capitol of NebraskaJon:
Lincoln, in Lancaster Co. ;)Scott:
Third: Is this just something you decided to do someday or did someone ask you to do it? Either way, I am highly impressed...Can I have your brain? I'll trade you this tasty door stop!Jon:
Mmmmmm.... door stops.... ;)Scott:
It was just a neat little script I wanted to write, and then we figured we'd use it to make a couple posters or similar items. We are going to do a couple other things with it in the near future, hopefully... not just the Tux poster.
I might just skip out of work early some day and try to drop by to see what you folks are up to, steal all your secrets, buy you out, drive my enemies from the company and hear the lamentations of their women...I've said too much.
001011110
In reply to Tux Kernel Poster by Macphisto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |