ImageSlicer Progress…

The past two weeks I have been working on a small tool to slice images using Python, PIL and pygtk. I decided to use Glade for the user interface, and it’s great. It really simplifies coding GTK applications and lets me concentrate on handling events, writing callbacks. It is still necessary to know how GTK works to correctly create the interface and define signals and callbacks. But after that I just load the Glade XML file, fetch those widgets I’m really interested in (windows, buttons and menuitems mostly), connect handlers to the signals, show the main window and enter GTK’s main loop. As long as the widget names and signal names stay the same, I can now start trying out changing the user interface.

I want the ImageSlicer let the user create, move and resize rectangles over an image. I also wanted the display of the image and the rectangles to be zoomable. Since there isn’t any GTK widget that remotely does something like that, I had to come up with something. At first I thought, I’d just use some canvas component. I started by playing around with GnomeCanvas, but it didn’t have many features I needed and did have many features I didn’t need. Then I tried out GooCanvas, which at first seemed to be just what I needed. But then I noticed, it really isn’t suited to displaying images and working with them on a pixel level. While GooCanvas supports zooming, it will interpolate (blur, smooth) images and draw rectangles between pixels (which also blurs them). This is, because it really is meant to be used for displaying and modifing vector graphics. So I went back to creating my own solution.

I use a GtkDrawingArea for displaying the image and slice rectangles. I store the image as a GdkPixbuf, and draw only the visible area. I get the the visible area from two GtkAdjustments (one for the x axis, one for the y axis) which I also use for scrolling in a GtkScrolledWindow. For the zoom scale I also used a GtkAdjustment. I recalculate the visible width and height whenever the window size or the zoom changes and store that in the page_size property of the corresponding GtkAdjustment. I use GdkRectangles for the slice rectangles but I’ll probably change that to something else, since I also need to store more data with the slices like name, image type and options for the image type.

So far I have image loading, scrolling, zooming and creating slice rectangles done, but I’m having trouble with getting the pixel offset of the pointer correct once zoomed in. This results in some strange, wobbly behaviour when dragging or resizing slice rectangles. Once I have that fixed, I can continue with creating a user interface for setting properties of slices.

I really want to add support for gimp files (xcf), so the user can load a gimp file and enable/disable layers. I also want some way of monitoring images for changes, so they can be reloaded if they’re edited. I already thought up a basic undo/redo system but I’ll need to get a bit further along with the other issues before I know if it will work well.

Advertisements

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.

Read more of this post

Making a theme for Xfwm4

Just finished creating two variations of a Xfwm4 theme. That’s a lot of work! Not only do you have to come up with some idea as what kind of theme to create (the creative spark, the inspiration) but also have to slice, cut and modify the mockup you finally came up with.

Read more of this post