Coder Social home page Coder Social logo

valery-barysok / rsvg-convert-aws-lambda-binary Goto Github PK

View Code? Open in Web Editor NEW

This project forked from serverlesspub/rsvg-convert-aws-lambda-binary

0.0 1.0 0.0 3.3 MB

Convert SVG images easily to PDF and PNG using AWS Lambda

Makefile 24.06% Shell 75.94%

rsvg-convert-aws-lambda-binary's Introduction

Static rsvg-convert binary for AWS Lambda

This is a statically linked rsvg-convert binary utility from the librsvg Linux package, allowing you to render SVG images to PDF and PNG on AWS Lambda using Cairo, deployable as an AWS lambda layer. It can help you get started quickly with RSVG inside Lambda functions.

Why?

The standard AWS Lambda Linux VM comes with imagemagick, but compiled without SVG support. In order to process SVG images, you either need to add SVG support to ImageMagick or use a custom tool. RSVG+Cairo is the best back-end for SVG processing in imagemagick anyway, so this binary gives you direct access to that toolkit.

Use within Lambda

You can use a pre-deployed ARN: arn:aws:lambda:us-east-1:145266761615:layer:rsvg-convert:2 or deploy yourself -- edit Makefile to set your deployment bucket etc, then just run make deploy.

The binary will be in /opt/bin/rsvg-convert inside your Lambda container.

Download the binary

Grab the binary from the vendor directory

Usage:
  rsvg-convert [OPTION…] [FILE...] - SVG Converter

Help Options:
  -?, --help                                                  Show help options

Application Options:
  -d, --dpi-x=<float>                                         pixels per inch [optional; defaults to 90dpi]
  -p, --dpi-y=<float>                                         pixels per inch [optional; defaults to 90dpi]
  -x, --x-zoom=<float>                                        x zoom factor [optional; defaults to 1.0]
  -y, --y-zoom=<float>                                        y zoom factor [optional; defaults to 1.0]
  -z, --zoom=<float>                                          zoom factor [optional; defaults to 1.0]
  -w, --width=<int>                                           width [optional; defaults to the SVG's width]
  -h, --height=<int>                                          height [optional; defaults to the SVG's height]
  -f, --format=[png, pdf, ps, svg]                            save format [optional; defaults to 'png']
  -o, --output                                                output filename [optional; defaults to stdout]
  -a, --keep-aspect-ratio                                     whether to preserve the aspect ratio [optional; defaults to FALSE]
  -b, --background-color=[black, white, #abccee, #aaa...]     set the background color [optional; defaults to None]
  -v, --version                                               show version information
  --base-uri                                                  base uri

Using custom fonts

RSVG uses Pango, and Pango uses Font-Config to load fonts. To use a custom set of fonts, you'll need to provide a trivial fonts.conf file somewhere and point to it using the FONTCONFIG_PATH environment variable. For example, put the fonts into the fonts subdirectory of your application, then add this file to your application root dir as fonts.conf:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <dir>./fonts/</dir>
  <cachedir>/tmp/fonts-cache/</cachedir>
  <config></config>
</fontconfig>

Then run FONTCONFIG_PATH=<APP-ROOT> <RSVG_DIR>/rsvg-convert input.svg -o output.svg

Versions

Compiled with AMI ami-60b6c60a, 29 October 2016, with the following library versions:

  • cairo: 1.12.14
  • pango: 1.28.4
  • libcroco: 0.6.8
  • gdk-pixbuf: 2.28.2
  • librsvg: 2.26.3

These are all a bit old, but are compatible with the other libraries available through YUM for the Amazon Linux instance. To get a more recent version built, modify compile-static.sh to include the appropriate versions of dependencies.

Creating a fresh compilation

  1. Create an AMI
  2. ssh to the AMI as ec2-user
  3. copy the files from the src directory to the VM.
  4. on the VM, run system_init.sh
  5. on the VM, run compile-static.sh

Testing on a (non-Lambda) AWS Linux VM

The binary will work on a plain-vanilla AWS Linux VM, but needs some additional packages (these are already available on the VM used for Lambda functions).

sudo yum install cairo libtiff -y

Copyright and license

GNU GENERAL PUBLIC LICENSE. Copyright (C) 1989, 1991 Free Software Foundation, Inc. Original LibRSVG license.

rsvg-convert-aws-lambda-binary's People

Contributors

gojko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.