Scale Any Sewing Pattern to a Printable PDF (with Python)

by Emelieh21 in Craft > Sewing

136 Views, 4 Favorites, 0 Comments

Scale Any Sewing Pattern to a Printable PDF (with Python)

Screenshot 2024-11-10 at 13.55.03.png
Screenshot 2024-11-10 at 13.52.25.png
FH0RA9HM3A6EOMK.png

Finding the correct pattern is probably the part that I spend by far most time on in any sewing project. Sometimes I find something that looks good on the internet, but it is not the size that I need it to be or it's just a picture and I can not download it to print it.

For this reason, I looked for an automated way to take an image of any size, convert it to the size I want it to be and then put it on A4 sheets, so the only I thing that I need to do is print it out, glue it together and start sewing already.

In this Instructable I am sharing the solution I came up with. It is a Python program you can also run on your computer (no programming skills required, but it does get a little bit technical).

I would like to make a proper application out of it at some point, but already wanted to share in case it could be useful to anybody else.

Supplies

  1. Hardware requirements:
  2. Computer
  3. Scanner
  4. Printer
  5. A4 sheet to draw on
  6. Pen
  7. Software requirements:
  8. Python 3.8+ (download Python)
  9. Poetry (see python-poetry)

Draw Your Pattern

IMG_20241109_142926_010.jpg
IMG_20241109_143849_256.jpg

Use one A4 sheet for each part of your pattern and draw with a dark pen or marker. It does not matter what size it is, since we will be resizing it later on.

I am rescaling one of my own patterns that I used in this Instructable, because I want to make this jacket again in a slightly bigger size.

What I did was open the PDF of the existing pattern on my laptop, zoomed out so it would easily fit on an A4, put a paper sheet on top of my screen and copied the lines with a pencil.

If you want to test first without drawing anything, you can find some example sewing patterns that I have used in the past here (they are all for dogs though).

Scan Your Drawings & Convert to PNG (if Necessary)

IMG_20241109_144603_340.jpg
main-part.png
collar.png

Scan the patterns, ideally in PNG format. Since my printer scans only in PDF or JPEG format, I used JPEG and converted the files afterwards to PNG with a free online converter tool (jpg2png).

I connect to my printer via my smartphone, so I needed to share the files to myself somehow. To do this I used email rather than WhatsApp, because by default WhatsApp compresses images (and we do not want that).

Download or Clone Pattern-Scaler and Run It Locally

Screenshot 2024-11-10 at 11.04.29.png
Screenshot 2024-11-10 at 11.05.08.png

Option 1: Manual download

Go to https://github.com/Emelieh21/pattern-scaler, click on Code and then on Download ZIP (see image). Unzip the folder.

Open the terminal in the pattern-scaler folder (on MacOS: right click the folder in the Finder and click on "New Terminal at Folder", on Windows: right click the folder and click on "Open in Terminal").

In the terminal type the following and hit enter:

poetry install


Option 2: Clone with Git

If you have Git installed on your PC you can clone the repository with:

git clone https://github.com/Emelieh21/pattern-scaler.git
cd pattern-scaler
poetry install


Start the application

When the installation is finished, run:

poetry run uvicorn --reload --host localhost --port 8001 "app.main:app"

If you see "Application startup complete" appear in your terminal, everything is running fine and we are good to go. To confirm you can go to http://localhost:8001/docs and you should see your interactive FastAPI documentation.

Calculate Your Desired Height or Scale Factor

Screenshot 2024-11-10 at 12.38.34.png

First of all, we need to decide what size we want the pattern to be or with what factor we want to multiply it.

For this, it helps to understand that the pattern scaler works in the following way:

  1. It detects the image in your drawing
  2. Calculates how large it currently is (height and width)
  3. Rescales it to the size you want it to be, either by making it the desired height that you specify or multiplying the current height and width with the scale factor you define
  4. It splits the rescaled image in as many A4s as it needs, so it can be printed

As you can see in the image attached, the image is always detected as a rectangle or a square. It is important to keep this in mind when you are calculating your desired height (especially when you drew your image diagonally).

I want to scale my patter to be 60cm (approximately 25% bigger than it originally was).

Run the Pattern Scaler

Screenshot 2024-11-10 at 13.08.40.png
Screenshot 2024-11-10 at 16.48.35.png

When your API is running as explained in Step 3, go to http://localhost:8001/docs.

Click on POST /scale_pattern and then on Try it out

Put either the desired_height, desired_width, scale_factor_height or scale_factor_width (as long as one of them is filled in, it should work).

As said, I want my pattern to be rescaled to a height of 60cm, so I am defining the desired_height as 60.

After this, I clicked Choose file and selected the main-part.png that I generated in Step 2.

Click Execute.

If you have other parts that you need to rescale to the same proportion, look at the logs in the terminal and copy the scale factor (see image). I will also rescale the collar, so I will keep in mind that my scale factor 3.24.

Small note: if the API fails to convert when you try to use it a second time, restart it and try again. It seems like there is some bug in the interactive FastAPI docs that does not allow to execute twice in a row without changing the selected file (at least on my computer). Alternatively, you can also call the API via a curl command in the terminal, instead of the FastAPI docs (never had issues with that).

Download & Print Result

Screenshot 2024-11-10 at 13.15.17.png
F0EQH7LM3BLUYDA.png
Screenshot 2024-11-10 at 17.14.36.png
FAP398QM3A6ESOC.png

If the call is successful you can click "Download file" to download the file.

I recommend to print one page first to see if the little grey square in the left upper corner is 1cm by 1cm. This is to check if your image is not being resized by the printer (this would not be good for the end result). If the square has the expected size, continue printing the full pattern.

Also, check for empty pages (so you can exclude them from printing). Since the image detected and rescaled in a rectangular format, empty pages are sometimes included in the result.

I have added the result of my main body part in attachment.

Cut Your Pattern and Glue It Together

Screenshot 2024-11-10 at 17.19.01.png
Screenshot 2024-11-10 at 17.19.18.png
Screenshot 2024-11-10 at 17.19.36.png
Screenshot 2024-11-10 at 17.39.15.png

The pages have lines on the side and letters indicating which page goes where. This should help to figure which parts to glue together. Cut the parts and make sure to leave the extra space on the side on one of the parts that go together (for the glue).

Repeat Step 5 Until 7 for Other Parts

Screenshot 2024-11-10 at 17.41.25.png
Screenshot 2024-11-10 at 18.30.04.png

I converted also the collar of the jacket to be the correct size, by putting the scale_factor_height to 3.24 (see screenshot). Unfortunately, since I drew this part diagonally, it managed to need four pages for the rescaled version, even though it is a relatively small part. I should have drawn it straight.

If I have time I will redo it and upload a better version in the future.

Downloads

Our Pattern Is Ready

Screenshot 2024-11-10 at 18.31.28.png

Now I can finally sew the this jacket for my slightly bigger dog Mandy :)