Wednesday, September 25, 2019

Removing the background & converting a JPEG or PNG to SVG

Disclaimer: this isn't a strictly 3D printing post. Blender will consume SVG files, and with some effort can MAKE svg files...but I needed some SVG files for a project, so I will go over how it works for me.

For my current project, I need to remove the background of a photo, then turn the subject into a SVG file - all so I can use a laser cutter to etch animals onto slate coasters. 



I'll be using Illustrator...CS3. I was a student once, and the Indesign/Photoshop/Illustrator package was $300 as a one-time purchase. I'm not using this for commercial purposes (if I end up needing to do commercial purposes, I might come back and show how to do this in Inkscape). I'm sure the habits are very similar.

I start with a 10 cm x 10 cm square as the document size - the size of the coaster I'll be etching with a laser. (This can also be useful for someone using a Cricut - my girlfriend got one last week.)

Next, under File>Place, I put my image file on my document - this also creates the first layer. The image is ideally too big - scaling down keeps details, while scaling it up will lose them. Regardless, select a corner with your right mouse button, hold down shift (so the image will scale on its X/Y at the same rate)...and then scale your picture to fit in the box. If you used a PNG, you're fine. If you used a JPEG, go to Object>Rasterize and click okay in the dialog box. (If you don't rasterize your JPEG you will not see "Live Trace" later.)

Rasterized Baby Leopard scaled down to fit in the 10 cm x 10 cm frame (Layer 1)
You have the photo within the box - let's take a step back and do some other prep work. Under Window>Layers - you'll want that visible. Under View>Show Transparency Grid, you want the background to be transparent - checkered instead of pure white. Also under View>Smart Guides, I like turning those off for this kind of project. (Feel free to turn them back on later - you can decide for yourself what you like.)
View Menu for adding Show Transparency Grid & turning off Smart Grid

As a good practice, create a new layer and select it - this is where you'll do your tracing. Both your foreground and background should be a white box with a red line through it...this means any fill you have will be transparent. (If you don't do this step, you'll see your picture being covered up as you trace.)

Transparent fill
With the pen tool, start right-clicking along the border of your image. You can make curves with a curve tool, but...more learning. When I hit an area that needs more of a curve, I'll just place more vertices. Once you get back around to the start, click from your first spot, and it will automatically make it complete. (If you had Smart Guides from earlier turned on, it would try to suggest certain angles for the next vertex.)

The red vertices are pretty small, so I often zoom in for close details

With that done, drag that part of the layer 2 on top of that the original layer. Under Select>All, it should highlight both the image and the border you just drew. Object>Clipping Mask should cut out the background!

The clipping can be more exact, but the conversion to SVG will change the detail level too.
Now comes a more basic "turn this into an svg" - you can always save an Illustrator file as an SVG. But I needed a black with transparency object. With the selection tool (not pen tool), double right-click on the new image. You want a "Live Trace" button to show up in the top bar, and for some reasonable-but-not-known-to-me, it takes two double-clicks. Press "Live Trace". Boom - white and black...but not transparent. There's a button in the bar that opens up tracing options, and you'll want to check the "Ignore White" checkbox. (You'll notice now that it's just transparent and black now.) I would also recommend experimenting with different amounts of Threshold, instead of sitting at 128. The higher the number, the more black. Min. Area is going to give you a higher detail at a smaller number.

Trace Dialog Box

And that's it. Save as a SVG, and you're done! Wish you good luck translating this into your vector-based experiences.

No comments:

Post a Comment