You are here

Cross-stitchify v2.1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Rate this item!
cross-stitchify_v2_1.zip15.03 KB

Someone on an email list I belong to asked about ways of making a counted cross-stitch pattern from a photo. There are commercial packages that do this, but it seemed like something GIMP could do, and I wanted some Python practice.

Attached is a zip file containing the following files:

  • - Python script for converting a photo to a cross-stitch pattern
  • floss.html - an HTML document listing available cross-stitch floss colours by numbered index, common name, RGB and hex values (culled from

I used the Photoshop tutorial found here as my starting point. The script performs the following operations:

  • Pixellates, adjusts brightness & posterises according to user settings
  • Scales down the pixellated image to increase performance
  • Checks each colour of each mosaic tile, and performs "best matching" colour exchange against the palette of available floss colours
  • Scales up pixellated image for next operations and for readability
    vAdds grid in new layer
  • Adds text labels for each colour with floss' index number
  • Creates a text file listing all floss needed, and in what quantities

It appears in the menus under Filters > Decor > Cross-stitchify... It takes quite some time to run as I need to iterate through each tile of the image twice, and any interruption during the label phase can crash the script, but the output is quite good. The entire image can be printed for use as the pattern, or just the grid if printing in B&W.

UPDATE: version 2.0 - added creation of text file with list of what colour floss, and how many stitches of each, are used. Also allowed for greater range of mosaic sizes to accommodate wider range of images.
UPDATE: version 2.1 - added OS check: win32 opens text file, other OS displays message with path to file.

Code License: 
GIMP Version: 
Scripting Engine: 


I think line 474 should read

if (currColor[0:3]) != (newColor[1:4])

instead of

if (currColor[0:2]) != (newColor[1:3])

The current version doesn't take blue into account when comparing colours, which is a problem if the design has adjacent black and navy squares.

Thanks for this by the way, it's saved me loads of effort :)

nevermind - redundant

I have put the .py file in ~jim/.gimp-2.6/plug-ins but it does not appear in any menu. The Help file says to put it where the compiled plug-ins go, but fails to identify that location...

I also added links in ../modules and ../scripts but no luck.

How do I get the file recognised?


Problem solved.
The .py file needs to have the execute permission set.

You can put the file here C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins, and it will load into GIMP 2.+

Today I downloaded the script to my mother and she told me he was giving error. I tested and got the following feedback: --------------------------  Traceback (most recent call last):     File "/usr/lib/gimp/2.0/python/", line 692, in response        dialog.res = run_script(params)     File "/usr/lib/gimp/2.0/python/", line 353, in run_script        return apply(function, params)     File "/usr/lib/gimp/2.0/plug-ins/", line 458, in cross_stitch        theImage.resize(widthNew, heightNew, 0, 0)  TypeError: integer argument expected, got float -------------------------- It looks like the same bug previously mentioned in other posts below. * I do not know if it changes anything in the case, but here we use Linux at home.

Can you help? :)

Rodrigo Boechat

Oops, after working out how to fix all by myself and posting this note, I just saw the reply from TikoQeri - apologies for the doubling up of the reply.

This can be fixed by making similar change in two places within the script. I am not saying that this is the best fix, but it deals with the error reported. My version of GIMP is 2.8.4.

First place is about line 456 in the file.
replace these two lines:

widthNew = widthOld * mosaicModified
heightNew = heightOld * mosaicModified


widthNew = int(widthOld * mosaicModified + 0.5)
heightNew = int(heightOld * mosaicModified + 0.5)

Then at about line 493, replace these two lines:

widthNew = widthOld * mosaicModified
heightNew = heightOld * mosaicModified

widthNew = int(widthOld * mosaicModified + 0.5)
heightNew = int(heightOld * mosaicModified + 0.5)

I am not sure if the + 0.5 is required, but I included it "just in case".

I just ran into the same error.To fix it, just make the following changes in two places in the plugin file (in my case it is: /usr/lib/gimp/2.0/plug-ins/ - lines 456-457 and 492-493


  widthNew = widthOld * mosaicModified

  heightNew = heightOld * mosaicModified

Change to:

  widthNew = int(widthOld * mosaicModified)

  heightNew = int(heightOld * mosaicModified)

For anyone interested in using this script and is running Ubuntu Linux: Open the script in a text editor.

Change line 570 from:

pdb.gimp_message("Text file saved as: " + path)


os.system("gedit"+ " " + path)

Save the script file and make sure the new version is in your plug-ins directory. This will start the gedit text editor and open the output file. I have only tried this on LinuxMint9 (Isadora), which is based on 10.04 Lucid Linux. If you prefer another text editor, try replacing "gedit" with your favorite editor. Note the quoted space between gedit and the path variable.


PS: There may be a more "elegant" way to do this - getting the OS to open in whatever the user's default text editor might be - I'm still pondering and figuring out the Linux shell as I go...

Some systems may have a sensible-editor alias - probably all the Debian-based ones:

There's also the EDITOR environment variable:


Subscribe to Comments for "Cross-stitchify v2.1"