If you'd like to upload plug-ins, please create an account below. Otherwise (e.g. for download or commenting) you do not need one! Enjoy :-)
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:
I used the Photoshop tutorial found here as my starting point. The script performs the following operations:
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.
| Attachment | Size |
|---|---|
| cross-stitchify_v2_1.zip | 15.03 KB |
Comments
symbol instead of number
My wife loves this - no other cross stitch app. for ubuntu gnome (there is a KDE app - kxstitch - but many problems compiling on gnome, so:
How about changing the floss colour number to show a symbol, anything from standard fonts would do - letters, etc., with a listing of symbol to floss number. This would be more like regular cross stitch applications and allow easier reading of final chart, and maybe allow smaller mosaic size without losing readability.
Also, one of the older posts here - being able to limit the palette size would make this really useable - haven't seen any further work on this - is it a possibility? I would love to but know absolutlely nothing about computers except as a "normal"user.
Thanks
Where to load?
I downloaded Python and the script. What folder should the cross-stitch.py and the floss.html files be loaded into so that I see Filters > Decor > Cross-stitchify ?
Also: floss.html = red herring
You don't need to add floss.html anywhere specific, it is supplied as a key to the numbered indicators in the final pattern. It does not actually interact with the script, it is only for reference..
Some Helpful Info
Here is a good quick guide to installing Python plugins:
http://meetthegimp.org/how-to-install-python-plugins-under-gimp/
How to use?
Hi,
I have been playing with your plugin, and it is not clear to me exactly what the 3 parameters do. What does the mosaic setting do? What about brightness? I understand that the posterize sets the number of posterization levels. That seems a bit non-intuitive to me. I would rather specify the number of colors I want to use directly. I guess something like converting to indexed colors with a specific number of colors in the palette? I might try to learn some python so I can mess with that myself.
Interesting Idea
The Mosaic parameter sets the size of the "pixels" in the final pattern (if you want each stitch represented by a 20x20 pixel square, set it to "20"). The default value (10) is the smallest I can make the squares to fit the text without making them unreadable.
As for setting the number of colours, I never thought of doing that. I wrote it assuming you wanted to get the closest to the look of the original image using any available floss colour. The Posterize setting might help with that, but it doesn't give you a 1 to 1 correlation with number of colours.
I encourage you to get Python and fiddle with the script! It is really fun, and you can learn a lot.
Another error?
Just when the plugin is about to complete, I get this error:
AttributeError: 'module' object has no attribute 'startfile'
The details are:
Traceback (most recent call last):
File "/usr/lib/gimp/2.0/python/gimpfu.py", line 692, in response
dialog.res = run_script(params)
File "/usr/lib/gimp/2.0/python/gimpfu.py", line 353, in run_script
return apply(function, params)
File "/home/bob/.gimp-2.6/plug-ins/cross-stitch.py", line 567, in cross_stitch
os.startfile(file.name)
AttributeError: 'module' object has no attribute 'startfile'
Kind of answered my own question
After a little googling I figured out that os.startfile is just supposed to open the file up. Since that is just opening the text file that contains the listing, I just commented out that line for myself and it works quite well now.
If it helps your debugging, I'm running this under Fedora 10.
Updated
Try the new version.
Thanks for the follow-up
I wrote thus under Windows, and I don't have a linux installation to test. My research (i.e. 30 seconds of Googling) reveal that to launch a file "with its appropriate application" is not a trivial thing to do in Linux. I suspect your solution is best. I think I might check the OS, and if it is not Win32 I will put a GIMP message box that states the location of the text file. Cheers!
What version of the gimp did
What version of the gimp did you write this for? I'm running gimp 2.4.7 and python 2.5.1. I keep getting an error message
Traceback (most recent call last):
File "/usr/lib/gimp/2.0/python/gimpfu.py", line 662, in response
dialog.res = run_script(params)
File "/usr/lib/gimp/2.0/python/gimpfu.py", line 347, in run_script
return apply(function, params)
File "/home/robin/.gimp-2.4/plug-ins/cross-stitch.py", line 448, in cross_stitch
theImage.resize(wNew, hNew, 0, 0)
error: could not resize image (ID 1) to 0x0, offset 0, 0
Any idea what is happening?
Thanks,
rhaben
Hmmm...
I wrote this using the most recent version of GIMP (2.6x). The error looks like it is trying to resize the image to nothing... I am wondering if the image is unusual in some way...
I posted a new version of the script. Try that, and tell me if you get the same result. If so, maybe you can post the image and I can test here.
Image size issue debugged
If you set theMosaic to something > 5, then the newHeight and Width are calculated to be 0.
#resize layer shrinking mosaic=5 to run faster
#mosaicModified = 5 / theMosaic
#my fix
mosaicModified = float(5) / (float(theMosaic))
print "Mod Mosaic = %d" % mosaicModified
widthNew = widthOld * mosaicModified
heightNew = heightOld * mosaicModified
I have been running with the cast operators just fine.
Possible enhance
Would it be possible to have in another layer a list with all the colors used and the number of stitches of each color, in order to have a buying list. Now you have to "eye-scan" the output looking for X (15 by default) different colors.
Thank you, great job.
Excellent idea
I was thinking about how I could enhance the script, and that sounds ideal! I will have a think, and post the new version here when I have worked out the best method.
Home palette
Is there a way for me set the palette according to the threads I have in my basket? I might have 40 threads and want to create patterns without needing to buy more. Best of all would be if the tool let me choose how many threads I'm willing to buy (default 0) in addition to the ones I have. It would then list separately the ones you have to buy.