Cross Stitch Pattern Generator




Introduction: Cross Stitch Pattern Generator

My mother loves to cross-stitch and crochet. Her biggest problem is finding the right patterns for what she needs to do. I've seen her buy dozens of books with patterns as well as have my brother draw on grid paper a unique design. Many of the images are easy to find with a quick Google search, so I set out to take a jpeg from a Google Image search and turn it into a cross-stitch of crochet pattern for my mother!

The way I did this is with a JAVA program, however, besides reading/writing the image, I used all basic primitives so anyone could easily take what I've done and do it in their own language. The full source code is available here to download and use or translate.

Step 1: Take the Input Parameters

This is meant to take in a jpeg. This part has some fairly JAVA specific methods, but to port it to your language of choice should be trivial. Here we receive the input parameters, verify the input image exists and make sure we can create the output file.

Step 2: Example Image

For our testing, we will be making a cross-stitch ready pattern of the Instrucable mascot!

Step 3: Scaling the Image Down

The above code will take our rather large image of the mascot and resize it to the user specified dimensions. This results in a very tiny image. This very tiny image isn't very useful, but this is the resolution that we want. To make it useful, we now have to size it back up but make it seem as we're staying at this low resolution!

Step 4: Scale the Image Back Up

Now we take our very small image, and we're going to re-produce each pixel 10 times in the X and Y direction. Then in between each of these 10x10 scaled up versions of our pixel, we're going to put a black line. This will give us our cross-stitch template effect!

Once that is done, you can write your image out and use it!

Step 5: Example Cross-stitch Pattern!

And here are some example patterns that I've made!

Step 6: A Note on Aspect Ratio

To use this effectively, when inputting your output dimensions try to preserve the aspect ratio or width / height as close as possible. Sometimes to fit a specific template, you're forced to smush a bit, but try to stay close.

For example, the input Batman image is 200 pixels wide, and 120 pixels height. It's wider than taller. So, when re-scaling it, I chose 50 pixels wide, by 30 pixels height. I just divided both sides by the same amount, and the result looks great. However, above you can see when I choose 50x50, changing the aspect ratio, makes the symbol looked squish compared to the original!



    • Creative Misuse Contest

      Creative Misuse Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Fix It! Contest

      Fix It! Contest

    13 Discussions

    This would work great for making perler bead patterns too. Thanks for sharing!

    1 reply

    I have actually used that exact batman pattern for crocheting.

    Very nice coding style! Can you show an example of which variables get updated when you setup your java file for a new .jpg image? Please include a sample directory path. When I tried to use your code I got a message in the output flow:

    Unable to process request. 0 requires three parameters:
    [1]: Full path and file name for Input Image(Ex:C:/images/funImage.jpg
    [2]: Full path and file name for Output Image(Ex:C:/images/funImage_crossStitch.jpg
    [3]: Number of rows in output
    [4]: Number of columns in output

    4 more answers

    Hi Sizzlewump,

    It looks like you forgot to add the input parameters. You have to fill out those for it to work. So for example, these are input parameters I just tried to get a new picture:





    The top one is a picture that exists, the second one is what the code will create and the third and fourth are the image dimensions of the created picture. I hope that helps!

    I think I'm missing some code or something. I have tried as you suggested but I get the same results using:

    public class CrossStitch
    public static void main(String[] p_args) throws IOException
    String imageToStitch = "C:/temp/spaceGhost2.jpg";//"C:/....."
    String outputImage = "C:/temp/spaceGhost2_CS.jpg";//"C:/....."
    int sizeX = 51;
    int sizeY = 51;

    Oh, I see the problem. Don't modify the code and add your variables, they are input parameters. If you're running from Eclipse or another IDE, You have to put them under PROGRAM Arguments. Then, those will populate the String[] p_args variable.

    If you DO want to just modify the code, then fill those out as you see fit, and comment out the try/catch that decipers p_args.

    Awesome! Thanks for clearing that up. I'm using JGrasp (I like that it's not resource intensive). It works fine without the try/catch block. I didn't even consider that.


    1 year ago

    Very clever idea! Thanks for sharing!

    Zooming in with MsPaint will give the image a pixelated look, but it won't make it in to a specific number of pixels, which are needed for cross stitching, crocheting and perler beading.

    ok. i didnt realize that it had to be a specific style. I just thought it was as simple as adding a grid and making X's. thanks for the info!