Shallow Thoughts : : May

Akkana's Musings on Open Source Computing and Technology, Science, and Nature.

Mon, 29 May 2006

Aid for Java Victims

Over dinner, I glanced at the cover of the latest Dr. Dobb's (a new article on Ruby on Rails), then switched to BBC World News. The first Beeb headline was Aid flow begins for Java victims.

I guess I was a little distracted from dinner preparations ... my first thought was "Are they going to give them all copies of Ruby and Rails?"

Then, of course, I remembered the earthquake. Oh, right, those Java victims!

(Not to make light of the situation there, which sounds grim. And just as I was writing this, I got email from the USGS Earthquake Notification Service reporting another aftershock in Indonesia, this one magnitude 5.6. I hope it doesn't make matters worse.)

Tags:
[ 22:05 May 29, 2006    More programming | permalink to this entry | ]

Sat, 27 May 2006

New Pandora, Reversing Layers, and Script-Fu Booleans

Dave thought I wasted too much presentation time reversing the layers in my panorama example prior to running Pandora. I'm sure he's right.

The problem is that GIMP's "Open as Layers", if you select multiple layers, opens them in the opposite direction from the way you'd generally expect to use them in a panorama, with the lexigraphically first layer on the top of the stack rather than the bottom.

The very next day, someone showed up on IRC asking how to reverse layers, because "Open as Layers" opened them in the wrong order to use for an animation.

At Mitch's suggestion, I wrote a reverse-layers script-fu (which Mitch improved by pointing out that it didn't handle the possible error case of a floating layer. As it happens, re-ordering floating layers works fine in current CVS, but apparently it's not supposed to. I suspect being able to move layers without alpha off the bottom position in the stack may also be a bug, so I added a guard against that). (Update: No, it turns out it's intentional that non-alpha layers can be moved anywhere in the stack in 2.3.)

Layer->Stack->Reverse Layer Order is now included in CVS GIMP, but for users of earlier versions I've made it available: reverse-layers.scm.

Meanwhile, I made a new version of Pandora which can build a panorama in either direction. I still find it slightly jarring to assemble a panorama from right to left after building them from left to right for so long, but maybe I'll get used to it.

I caught another bug at the same time: I was testing one of the parameters set in the GIMP dialog (which sets a toggle to either TRUE or FALSE) like this: (if use-mask (do-stuff))

That doesn't work in script-fu. Turns out TRUE is just an integer, while if apparently only tests for Lisp nil or non-nil. So you have to say (if (= use-mask TRUE) (do-stuff)) if you want tests to work against booleans coming from GIMP dialogs.

Tags:
[ 23:22 May 27, 2006    More gimp | permalink to this entry | ]

Fri, 26 May 2006

"Beginning GIMP" is shipping!

It's been a busy couple of weeks. My book (Beginning GIMP: From Novice to Professional) finally started arriving on people's doorsteps.

I first found out it was shipping from an email from a reader in Ohio: "I just received your book, and I have a question ..." He was the first of the Amazon shipments.

Over the next few days, more Amazon shipments started trickling in -- my mom got hers, a couple of friends got their copies. But it was nearly a week before either I or the home office of Apress received our copies, so in the meantime I was pumping everyone I knew for information -- "How does it look?"

Finally my copies arrived. It's beautiful! I'm so happy with the printing job Apress arranged. Bright colors on thick glossy paper. The colors are surprisingly different from what I saw on the PDF that went to the printer -- the active window borders on all the screenshots (royal blue on my screen) are almost purple! Now I can better appreciate why people who print professionally care so much about details like ICC color profiles. Fortunately, I knew there might be some color shift, so none of the figures in the book depend on exact colors (the RGB color circles aren't precisely Red, Green and Blue, but I'm sure readers will understand them).

So now I'm on the lecture/booksigning circuit. What fun! I've only given a couple of talks so far; last night was a PenLUG talk that went well, with lots of audience questions. The audience ranged from beginners to experienced graphics programmers to someone who's interested in using GIMP in a scientific context (comparing images; I told him about the geologist I talked to a few months ago who was doing just that, using Difference or Subtract layer modes to compare two aerial photos of the same area) to a professional photographer who uses GIMP in his work. One of the great side benefits of speaking about GIMP is getting a chance to hear all the ways people use it for different purposes.

I made some business cards to hand out, but no one takes them. That's okay: it was a good excuse to fiddle with my gimplabels script-fu and learn how to print really nice business cards from GIMP. Making business cards is easy with gLabels, but since it uses gnome-print it can only print using the system's default settings, which makes for really chintzy looking, pixellated cards. Gimp-print, on the other hand, can print in high resolution to nice glossy photo-quality card stock.

I'm gradually learning how to give a better GIMP talk, collecting interesting examples to show and minimizing the time spent fumbling over menus or waiting for progress bars. And dealing with the occasional glitch: last night, SIOX for some reason refused to select my flower image, after working perfectly the hundred or so previous times I've used it on that image. (What timing! Just last week I also received my ATM-B award from Toastmasters. Too bad outside GIMP talks don't count toward the next level.)

Fortunately GIMP is very visual, so it's easy and fun to find whizzy examples and techniques that most people haven't seen before. People have lots of interest in GIMP and image editing in general, and they want to hear more about it and have lots of questions. It's a topic everyone can appreciate. After all, who doesn't like looking at cool images?

Tags:
[ 11:32 May 26, 2006    More gimp | permalink to this entry | ]

Sun, 14 May 2006

Linkifying with Regular Expressions

I had a page of plaintext which included some URLs in it, like this:
Tour of the Hayward Fault
http://www.mcs.csuhayward.edu/~shirschf/tour-1.html

Technical Reports on Hayward Fault
http://quake.usgs.gov/research/geology/docs/lienkaemper_docs06.htm

I wanted to add links around each of the urls, so that I could make it part of a web page, more like this:

Tour of the Hayward Fault
http://www.mcs.csu hayward.edu/~shirschf/tour-1.html

Technical Reports on Hayward Fault
htt p://quake.usgs.gov/research/geology/docs/lienkaemper_docs06.htm

Surely there must be a program to do this, I thought. But I couldn't find one that was part of a standard Linux distribution.

But you can do a fair job of linkifying just using a regular expression in an editor like vim or emacs, or by using sed or perl from the commandline. You just need to specify the input pattern you want to change, then how you want to change it.

Here's a recipe for linkifying with regular expressions.

Within vim:

:%s_\(https\=\|ftp\)://\S\+_<a href="&">&</a>_

If you're new to regular expressions, it might be helpful to see a detailed breakdown of why this works:

:
Tell vim you're about to type a command.
%
The following command should be applied everywhere in the file.
s_
Do a global substitute, and everything up to the next underscore will represent the pattern to match.
\(
This will be a list of several alternate patterns.
http
If you see an "http", that counts as a match.
s\=
Zero or one esses after the http will match: so http and https are okay, but httpsssss isn't.
\|
Here comes another alternate pattern that you might see instead of http or https.
ftp
URLs starting with ftp are okay too.
\)
We're done with the list of alternate patterns.
://
After the http, https or ftp there should always be a colon-slash-slash.
\S
After the ://, there must be a character which is not whitespace.
\+
There can be any number of these non-whitespace characters as long as there's at least one. Keep matching until you see a space.
_
Finally, the underscore that says this is the end of the pattern to match. Next (until the final underscore) will be the expression which will replace the pattern.
<a href="&">
An ampersand, &, in a substitute expression means "insert everything that was in the original pattern". So the whole url will be inserted between the quotation marks.
&</a>
Now, outside the <a href="..."> tag, insert the matched url again, and follow it with a </a> to close the tag.
_
The final underscore which says "this is the end of the replacement pattern". We're done!

Linkifying from the commandline using sed

Sed is a bit trickier: it doesn't understand \S for non-whitespace, nor = for "zero or one occurrence". But this expression does the trick:
sed -e 's_\(http\|https\|ftp\)://[^ \t]\+_<a href="&">&</a>_' <infile.txt >outfile.html

Addendum: George Riley tells me about VST for Vim 7, which looks like a nice package to linkify, htmlify, and various other useful things such as creating HTML presentations. I don't have Vim 7 yet, but once I do I'll definitely check out VST.

Tags: , , , , ,
[ 13:40 May 14, 2006    More linux/editors | permalink to this entry | ]