5

In PHP, it's quite easy to use GD to draw text onto a raster canvas in a certain font (according to a TTF file held on the server), and output it as a PNG or JPEG.

I want to do roughly the same thing, but to draw the text as a vector outline and output it as an SVG.

(I do not want to embed the font itself in the resulting SVG, as the font is not licensed for that.)

Is there any PHP library that provides this sort of functionality?

callum
  • 34,206
  • 35
  • 106
  • 163
  • Why do you want to destroy the text in the svg? Only to get around licensing issues? Have you considered using a similar but freely available webfont with the generated svg output? By converting the text into svg paths the viewers lose all ability for searching and selecting the text. – Erik Dahlström Nov 28 '11 at 16:38
  • Yes, licensing issues. The font is essential (brand guidelines). I don't need the SVG itself to be searchable. I am going to use the SVG for an image-replacement technique, ie to just visually hide the text and display the SVG as a CSS background instead (in browsers that support it). The point of using SVG (as opposed to PNG) is to have a zoomable interface with no loss of quality (where supported). – callum Nov 29 '11 at 10:35

2 Answers2

3

It's possible to script inkscape to do this.

The following command opens "example.svg" and selects all shapes in the file and converts them to paths, and then saves and closes the file.

inkscape --verb EditSelectAll --verb ObjectToPath --verb FileSave --verb FileClose example.svg
Erik Dahlström
  • 59,452
  • 12
  • 120
  • 139
  • Awesome. Where'd you find this API? Is it possible to open a different filetype (for instance, `.ai) and export as something like `.svg`? – corysimmons Jan 15 '14 at 16:31
  • 1
    That should be possible. Found in the manual, e.g http://inkscape.org/doc/inkscape-man.html and http://tavmjong.free.fr/INKSCAPE/MANUAL/html/CommandLine.html. – Erik Dahlström Jan 16 '14 at 08:06
0

I was able to find CleverSVG trough searching, however I did not try this myself, and I am unsure if it will be able to draw text without forwarding the font.

Qqwy
  • 5,214
  • 5
  • 42
  • 83