Comments (3)
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.
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.
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)
- Consider creating a new class to handle attribute conversion
- Select custom fonts HOT 6
- The VERSION constant is set at the global level HOT 6
- collision HOT 1
- generate single elements to append on svg HOT 15
- Support for nested SVGs HOT 3
- Is it possible to nest tspan elements inside text elements? HOT 5
- XML escaping HOT 9
- The 'use' element outputs 'xlink-href=',shoud it be xlink:href=? HOT 4
- Conversion utility HOT 2
- Should the template argument be moved to #render and #save?
- how to code stops for a lineargradient HOT 2
- how to import css from external file HOT 3
- How to add a .png image from my PC to the svg canvas? HOT 2
- tspan elements always rendered with space inbetween HOT 4
- Variable scope issues HOT 5
- Wrap JSON data in a CDATA element HOT 6
- Convert to other image formats HOT 3
- Allow adding separate CSS style tags
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from victor.