Linux and Image Slicing

A while ago I created a new page on this blog for Xfwm theming tools. Basically I wanted to have one place for all the scripts and tools that make creating Xfwm themes easier.

Ever since then I have been mulling over quite a few ideas I had. And I always seem to come back to the same basic problem. Whenever you want to create a theme based on individual images (pixbuf theme in GTK slang), you just don’t have the right tools, at least on Linux.

The most common way to create a pixbuf theme is by first creating a single large mock-up that captures the basic concept. Then that mock-up is sliced up into individual images. And at this point the tool chain on Linux is broken, as there is no easy to use, yet flexible program to slice up images.

But what does that mean, “easy to use, yet flexible”?

By that I mean, I just want to open up a program, load my image or images into it, draw in my slices, set their properties and hit “Go”.

Using GIMP

I’ll exclude GIMP right from the start. While it can do most of what’s needed, it is simply not easy to use in this case. For the simple reason that I can’t set up a chain of operations to be done on an image or slice of an image.

Sure, I just need to hit R (rectangle selection), select an area, Ctrl+Shift+C (copy visible), Ctrl+Shift+V (paste as new image), Alt+B (open image menu), Alt+M (open mode menu), Alt+N (select indexed mode), Ctrl+W (close image, asks if I want to save first), select some options, and save the image.

Do that about 10 times and it’s slightly annoying. But do it for every change you make to your mockup and you’ll see why it’s just a no-go. Or imagine having more then 10 slices, like, maybe 84 as for an Xfwm theme… did I just hear some wincing?

But then you’ll say why don’t I just write a script that does all that for me? I already went that route, and it still doesn’t quite satisfy.

First it requires the creator to code (coders make bad artists and artists make bad coders).

Secondly GIMP only has two ways to specify arbitrary regions within an image: alpha layers and paths. Paths don’t snap to pixels, don’t stay rectangular and their display while moving and editing tends to be flickery and buggy. And alpha channels aren’t that much better either.

However the biggest disqualifier for any of them is neither can store more than a region and a name for that region. What if I wanted to save some of the slices as one type of image, and other as some other image type? What if I wanted some indexed, others saved as 24 bit PNG’s with alpha channel?

Command line tools

In my opinion, working with images – even when doing batch processing – requires a graphical interface. Especially when I want to “draw in my slices”. So most image batch processors that work on the command line, most notably imagemagick, disqualify here. They are very useful, but not in this case.

Using Inkscape

What!? Inkscape!? Stay with me, it’s possible, as long as you are contend with 24 bit PNGs. Open up Inkscape, import your image, resize the document size to the image and draw some (transparent) rects over the image. Then select one of the rects and export to new image using the area of the rectangle.

It basically is just a hack, something I did just to see how it would work. You have most of the same problems as with GIMP, or at least very similar ones. This process can’t be automated and you can’t set image type or image mode (rgb, indexed, grayscale, alpha…).

Others

Before I even contemplated writing the GIMP script I went to the great oracle of Google and searched for answers. But all I got was cryptic answers and esoteric mumbo-jumbo… or very limited answers I could have guessed myself…

To boldy go where no man has gone before

Finally I have come to the conclusion that if there isn’t a tool to easily slice images with I’ll write one myself. After all, it’s just a simple matter of programming, right!?

So far I have evaluated a few “Canvas” widgets for GTK, they all have their advantages and disadvantages, but I pretty much decided on GnomeCanvas. While not one of the more feature complete ones, it is one of the more commonly found canvas widgets in the most widely spread distributions.

Besides I really don’t want to burden potential users with downloading obscure dependecies and doing the autotools dance more than absolutely necessary.

Well, that’s it, and this is me getting my hands dirty with some Python, yey!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: