GithubHelp home page GithubHelp logo

Combine existing SVG files about victor HOT 3 CLOSED

00dav00 avatar 00dav00 commented on August 20, 2024
Combine existing SVG files

from victor.

Comments (3)

DannyBen avatar DannyBen commented on August 20, 2024 2

Victor was not designed for this, it was designed to generate SVG from within Ruby, from scratch.

However, you might be able to use the #append (aka << operator) feature, which allows you to merge any object that responds to #to_s, and returns an SVG string.

Notice, you will need to obtain the SVG string without any of its surrounding <svg> tags - only the "body".

Here is a sample, to hopefully get you on the right track. This takes two SVG strings, and merges them into one SVG object, while transforming (moving) one of them to a certain position.

require 'victor'
include Victor

logo = '<rect x="0" y="0" width="50" height="50" fill="red"/>'
qrcode = '<circle cx="50" cy="60" r="20" fill="yellow"/>'

svg = SVG.new viewBox: '0 0 100 100', style: { background: "#ddd" }
svg.build do
  append logo
  g(transform: "translate(10  10)") { append qrcode }
end

svg.save 'merged'

Remember, the #append method only needs a string, so if you are using the QR code gem, and if it has a method that returns the SVG string itself (without root node), you may be able to do it all in "one pass" from within Ruby - instantiate the QR object, get (not save) its string, and merge it with your logo that you obtain via File.read or however.

from victor.

00dav00 avatar 00dav00 commented on August 20, 2024 1

Closing the issue, never the less I think it would be nice to be able to open existing SVG to append things to them. ;)

from victor.

00dav00 avatar 00dav00 commented on August 20, 2024

Thanks for the quick reply @DannyBen, the info helps a lot.

I've found this method in victor-cli which I think will help me too:

Victor::CLI::SVGNode.load_file

from victor.

Related Issues (20)

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.