diff --git a/lib/squib/api/image.rb b/lib/squib/api/image.rb index b64d486..afc4d1d 100644 --- a/lib/squib/api/image.rb +++ b/lib/squib/api/image.rb @@ -30,6 +30,7 @@ module Squib def svg(range: :all, file: nil, id: nil, x: 0, y: 0, width: :native, height: :native) range = rangeify(range) file = fileify(file) + id = idify(id) range.each{ |i| @cards[i].svg(file, id, x, y, width, height) } end diff --git a/lib/squib/input_helpers.rb b/lib/squib/input_helpers.rb index ce1f9e0..9a88cd7 100644 --- a/lib/squib/input_helpers.rb +++ b/lib/squib/input_helpers.rb @@ -58,6 +58,14 @@ module Squib end module_function :radiusify + def idify(svgid) + unless svgid.nil? + svgid = '#' << svgid unless svgid.start_with? '#' + end + svgid + end + module_function :idify + def xyify #TODO: Allow negative numbers that subtract from the card width & height end diff --git a/samples/load_images.rb b/samples/load_images.rb index 5cb4ac8..3688bb6 100644 --- a/samples/load_images.rb +++ b/samples/load_images.rb @@ -10,5 +10,10 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do # SVGs can be scaled too svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250 + # We can also limit our rendering to a single object, if the SVG ID is set + # Squib prepends a #-sign if one is not specified + svg file: 'spanner.svg', id: '#backdrop', x: 50, y: 350, width: 75, height: 75 + svg file: 'spanner.svg', id: 'backdrop', x: 50, y: 450, width: 125, height: 125 + save prefix: 'load_images_', format: :png end diff --git a/samples/spanner.svg b/samples/spanner.svg index e4704b7..1f3a747 100644 --- a/samples/spanner.svg +++ b/samples/spanner.svg @@ -10,7 +10,7 @@ viewBox="0 0 128 128" id="svg2" version="1.1" - inkscape:version="0.48.4 r9939" + inkscape:version="0.48.3.1 r9886" width="100%" height="100%" sodipodi:docname="spanner.svg"> @@ -36,15 +36,15 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1680" - inkscape:window-height="988" + inkscape:window-width="1280" + inkscape:window-height="1002" id="namedview14" showgrid="false" inkscape:zoom="2.8284271" inkscape:cx="98.928938" inkscape:cy="62.194589" - inkscape:window-x="1432" - inkscape:window-y="109" + inkscape:window-x="1912" + inkscape:window-y="-8" inkscape:window-maximized="1" inkscape:current-layer="g3767" inkscape:document-units="in" @@ -60,8 +60,9 @@ x="5.3126979" height="501.3746" width="501.3746" - id="rect3765" - style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10.62539577;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + id="backdrop" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10.62539577;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" + inkscape:label="#rect3765" />