Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert text to paths?

I am trying to convert text to curves and paths for example:

Text = 'Welcome to python'

I am trying to convert this text to path. Also I am trying to get this path information as list of points.

I want to store text as paths in an SVG file.

Like when you convert text to outlines inside adobe illustrator for example.

I tried this example but this is not what I want: cairo example

import cairo

def text_extent(font, font_size, text, *args, **kwargs):
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 0, 0)
    ctx = cairo.Context(surface)
    ctx.select_font_face(font, *args, **kwargs)
    ctx.set_font_size(font_size)
    return ctx.text_extents(text)

text='Example'
font="Sans"
font_size=55.0
font_args=[cairo.FONT_SLANT_NORMAL]
(x_bearing, y_bearing, text_width, text_height,
 x_advance, y_advance) = text_extent(font, font_size, text, *font_args)
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(text_width), int(text_height))
ctx = cairo.Context(surface)
ctx.select_font_face(font, *font_args)
ctx.set_font_size(font_size)
ctx.move_to(-x_bearing, -y_bearing)
ctx.text_path(text)
ctx.set_source_rgb(0.47, 0.47, 0.47)
ctx.fill_preserve()
ctx.set_source_rgb(1, 0, 0)
ctx.set_line_width(1.5)
ctx.stroke()

surface.write_to_png("/tmp/out.png")
like image 605
Tawfiq abu Halawah Avatar asked Aug 05 '13 12:08

Tawfiq abu Halawah


People also ask

How can you convert selected text to paths in Illustrator?

Select the text with Selection tool. Choose Type > Create Outlines to convert the text to editable paths. Select the Text > Right Click and then Select Create Outlines.

What does convert text to paths mean?

When you convert text to a path, the text becomes a graphic object that cannot be altered. Still, Inkscape lets you change the converted text's look by reshaping it. This type of conversion assists in making wordmarks or logos.

How do you convert your Type to outlines?

To convert text to outlines, go Select > Select All. It doesn't matter if other graphic elements are selected. Select Type > Create Outlines from the menu. The text will become outlined and can't be edited as text (see the image below right).


1 Answers

You can use inkscape:

import subprocess
subprocess.call("inkscape in.svg --export-text-to-path --export-plain-svg out.svg", shell = True)

note: you'll have to install inkscape first

like image 166
TheInitializer Avatar answered Nov 12 '22 16:11

TheInitializer