The goal of this project is to convert SVG document + embedded SVG fontface
to PNG image using browser canvas
.
Let's get to work or Continue to read the story.
- Next.js & Express.js - Running server locally and quick React.js UI setup
- Isomorphic-Fetch - Building reverse proxy to bypass CORS for remote SVG Url's
- Finally, 💗 of this POC - img-conv.js
Well i tried imagemagick and Apache Batik
Both are best for image manipulation, but they dont do a good job of converting SVG with @font-face
CSS embedded for custom font to be converted into PNG image that we expect.
- Install the fonts on the system where conversion happens - ( No way on Linux VM's )
- Convert those fonts to SVG fonts using fontforge and embed it inside the original SVG document to be converted - ( Phew! tedious work damn! )
- Take a screenshot & use Photoshop - ( Wait what! )
Use browser canvas
to do the heavy lifting using simple Javascript program. ( Yay! )
Hmmm, You need a working browser to run this project ( I can live with that! )
Tips - Use a headless browser to run the modified version of this project to achieve your goal on cloud VM's
-
Make sure nodejs is installed on your local machine
-
Checkout the Repo to your local machine
-
Next run
yarn
on the project root from terminal -
Now run
yarn start
to start the server from terminal -
Copy the url printed on the terminal window to your browser whick looks similar to
http://localhost:3000
Sample test image is inside the folder image-samples
.
-
Now the server is up & running on your browser
-
Sample image will be available as
http://localhost:3000/sample/pockethash.svg
( static resource served fromimage-samples
folder ) -
Paste this link in the UI textbox and click send. Your PNG will be rendered.
-
Click on the download button below the rendered image to download the final PNG image.
-
To tweak output image settings, modify variables in
pages\index.js
.
Contribution and suggestions are welcomed.
Nirus