Giter VIP home page Giter VIP logo

rsvg's Introduction

RSVG

⚠️ WARNING: This is an experimental proof of concept. Read the code, use at your own risk ⚠️

Elixir library to render SVG into PNG using librsvg.

Usage

# Get some SVG (read from file, generate in memory, etc.)
svg = File.read!("example.svg")

# Render into PNG
png = RSVG.render(svg, :png)

# Write to file (or serve via phoenix/plug)
File.write!("example.png", png)

Installation

If available in Hex, the package can be installed by adding rsvg to your list of dependencies in mix.exs:

def deps do
  [
    {:rsvg, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/rsvg.

rsvg's People

Contributors

tallakt avatar teamon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rsvg's Issues

Does not build on OSX

I am running on a M1 macbook. librsvg is installed using brew.

I entered iex and tried to install the library from git. The installation failed.

Erlang/OTP 25 [erts-13.1.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

Interactive Elixir (1.14.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Mix.install([{:rsvg, "~> 0.1.0", git: "https://github.com/teamon/rsvg.git"}])
* Getting rsvg (https://github.com/teamon/rsvg.git)
remote: Enumerating objects: 36, done.        
remote: Counting objects: 100% (36/36), done.        
remote: Compressing objects: 100% (21/21), done.        
remote: Total 36 (delta 8), reused 35 (delta 7), pack-reused 0        
origin/HEAD set to main
mkdir -p ./priv
cc -g -O3 -ansi -Werror -I/opt/homebrew/Cellar/erlang/25.1.1/lib/erlang/erts-13.1.1/include -fPIC -shared -dynamiclib -undefined dynamic_lookup -I/opt/homebrew/Cellar/librsvg/2.55.1/include/librsvg-2.0 -I/opt/homebrew/Cellar/gdk-pixbuf/2.42.10/include/gdk-pixbuf-2.0 -I/opt/homebrew/Cellar/jpeg-turbo/2.1.4/include -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -I/opt/homebrew/Cellar/glib/2.74.3/include -I/opt/homebrew/Cellar/cairo/1.16.0_5/include/cairo -I/opt/homebrew/Cellar/glib/2.74.3/include -I/opt/homebrew/Cellar/glib/2.74.3/include/glib-2.0 -I/opt/homebrew/Cellar/glib/2.74.3/lib/glib-2.0/include -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/Cellar/pcre2/10.40/include -I/opt/homebrew/Cellar/pixman/0.40.0/include/pixman-1 -I/opt/homebrew/Cellar/fontconfig/2.14.1/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.39/include/libpng16 -I/opt/homebrew/Cellar/libxcb/1.15/include -I/opt/homebrew/Cellar/libxrender/0.9.10/include -I/opt/homebrew/Cellar/libxext/1.3.5/include -I/opt/homebrew/Cellar/libx11/1.8.2/include -I/opt/homebrew/Cellar/libxcb/1.15/include -I/opt/homebrew/Cellar/libxau/1.0.10/include -I/opt/homebrew/Cellar/libxdmcp/1.1.3/include -I/opt/homebrew/Cellar/xorgproto/2022.2/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/ffi -L/opt/homebrew/Cellar/librsvg/2.55.1/lib -L/opt/homebrew/Cellar/glib/2.74.3/lib -L/opt/homebrew/Cellar/gdk-pixbuf/2.42.10/lib -L/opt/homebrew/Cellar/glib/2.74.3/lib -L/opt/homebrew/opt/gettext/lib -L/opt/homebrew/Cellar/cairo/1.16.0_5/lib -lrsvg-2 -lm -lgio-2.0 -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -lintl -lcairo -o priv/rsvg.so c_src/rsvg.c
ld: warning: -undefined dynamic_lookup may not work with chained fixups
==> rsvg
Compiling 1 file (.ex)

10:50:24.792 [warning] The on_load function for module Elixir.RSVG returned:
{:error,
 {:load_failed,
  'Failed to load NIF library: \'dlopen(/Users/tallakt/Library/Caches/mix/installs/elixir-1.14.2-erts-13.1.1/4d9812d4f8daadd40fa0549837020dc5/_build/dev/lib/rsvg/priv/rsvg.so, 0x0002): tried: \'/Users/tallakt/Library/Caches/mix/installs/elixir-1.14.2-erts-13.1.1/4d9812d4f8daadd40fa0549837020dc5/_build/dev/lib/rsvg/priv/rsvg.so\' (no such file)\''}}

Generated rsvg app
:ok

Error on production: exception exit: {on_load_function_failed,'Elixir.RSVG'}

Hello there!

Got the following error when deploy to production:

  crasher:
    initial call: supervisor:kernel/1
    pid: <0.3748.0>
    registered_name: []
    exception exit: {on_load_function_failed,'Elixir.RSVG'}
      in function  init:run_on_load_handlers/0 
      in call from kernel:init/1 (kernel.erl, line 189)
      in call from supervisor:init/1 (supervisor.erl, line 330)
      in call from gen_server:init_it/2 (gen_server.erl, line 423)
      in call from gen_server:init_it/6 (gen_server.erl, line 390)
    ancestors: [kernel_sup,<0.3734.0>]
    message_queue_len: 0
    messages: []
    links: [<0.3736.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 610
    stack_size: 28
    reductions: 255

I tried to debug the method load_nifs that I think could be the issue, but it seems ok.

This other issue says that does not compile on linux, I can see the rsvg.so file on my priv dir, it means it was compiled, right?

Thanks,

Does not compile on Linux

Currently this lib does not compile on Linux:

  • Compile on Alpine
  • Compile on Ubuntu

Alpine

$ mix test --only os:alpine
...
#12 0.937 mkdir -p "/app/_build/test/lib/rsvg/priv"
#12 0.939 Package librsvg-2.0 was not found in the pkg-config search path.
#12 0.939 Perhaps you should add the directory containing `librsvg-2.0.pc'
#12 0.939 to the PKG_CONFIG_PATH environment variable
#12 0.939 Package 'librsvg-2.0', required by 'virtual:world', not found
#12 0.939 cc -g -O3 -Wall -Wno-format-truncation -fPIC -I/usr/local/lib/erlang/erts-13.1.2/include -shared  c_src/rsvg.c -o /app/_build/test/lib/rsvg/priv/rsvg.so
#12 0.959 c_src/rsvg.c:2:10: fatal error: librsvg/rsvg.h: No such file or directory
#12 0.959     2 | #include <librsvg/rsvg.h>
#12 0.959       |          ^~~~~~~~~~~~~~~~
#12 0.959 compilation terminated.
#12 0.961 make: *** [Makefile:20: /app/_build/test/lib/rsvg/priv/rsvg.so] Error 1
#12 0.963 ** (Mix) Could not compile with "make" (exit status: 2).
...

Ubuntu

$ mix test --only os:ubuntu
#13 0.748 mkdir -p "/app/_build/test/lib/rsvg/priv"
#13 0.752 cc -g -O3 -Wall -Wno-format-truncation -fPIC -I/usr/local/lib/erlang/erts-13.1.2/include -shared -pthread -I/usr/include/librsvg-2.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/aarch64-linux-gnu -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -lrsvg-2 -lm -lgio-2.0 -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -lcairo c_src/rsvg.c -o /app/_build/test/lib/rsvg/priv/rsvg.so
#13 0.873 Compiling 1 file (.ex)
#13 0.887 
#13 0.887 10:36:37.419 [warning] The on_load function for module Elixir.RSVG returned:
#13 0.887 {:error,
#13 0.887  {:load_failed,
#13 0.887   'Failed to load NIF library: \'/app/_build/test/lib/rsvg/priv/rsvg.so: undefined symbol: g_object_unref\''}}
#13 0.887 
#13 0.888 Generated rsvg app
#13 1.007 Excluding tags: [:os]
#13 1.007 
#13 1.016 =WARNING REPORT==== 14-Dec-2022::10:36:37.553777 ===
#13 1.016 The on_load function for module Elixir.RSVG returned:
#13 1.016 {error,{load_failed,"Failed to load NIF library: '/app/_build/test/lib/rsvg/priv/rsvg.so: undefined symbol: g_object_unref'"}}
#13 1.016 

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.