save_sheet¶
Lays out the cards in range and renders a stitched PNG sheet
Options¶
- range
default:
:all
the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
- sprue
default:
nil
the sprue file to use. If
nil
, then no sprue is used and the cards are laid out automatically using the parameters below. If non-nil, Squib checks for a built-in sprue file of that name. Otherwise, it attempts to open a file relative to the current directory. For more information on Squib Sprues, see Sprue Thy Sheets.- columns
default:
5
the number of columns in the grid. Must be an integer
- rows
default:
:infinite
the number of rows in the grid. When set to :infinite, the sheet scales to the rows needed. If there are more cards than rows*columns, new sheets are started.
- prefix
default:
card_
the prefix of the file name(s)
- count_format
default:
'%02d'
the format string used for formatting the card count (e.g. padding zeros). Uses a Ruby format string (see the Ruby doc for
Kernel::sprintf
for specifics)- suffix
default:
''
the suffix of all the filenames saved, just before the .png extension.
- rotate
default:
false
if
true
, all saved cards will be rotated 90 degrees clockwise. Possible values:true
,false
,:clockwise
,:counterclockwise
Supports arrays so you can rotate individual cards different ways if that’s how you want to roll, e.g.
rotate: [:clockwise, :counterclockwise]
- dir
default:
'_output'
the directory to save to. Created if it doesn’t exist.
- margin
default:
0
the margin around the outside of the sheet. Supports Unit Conversion.
- gap
default
0
the space in pixels between the cards. Supports Unit Conversion.
- trim
default
0
the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play). Supports Unit Conversion. Must be the same for all cards.
- trim_radius
default:
0
the rounded rectangle radius around the card to trim before saving. Supports Unit Conversion. Must be the same for all cards.
- rtl
default
false
whether to render columns right to left, used for duplex printing of card backs
Examples¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # require 'squib'
require_relative '../../lib/squib'
# This sample demonstrates how to use the various save methods
Squib::Deck.new(width: 825, height: 1125, cards: 16) do
background color: :gray
rect x: 38, y: 38, width: 750, height: 1050,
x_radius: 38, y_radius: 38, stroke_width: 2.0, dash: '4 4'
text str: (1..16).to_a, x: 220, y: 78, font: 'Arial 18'
# Here's what a regular save_png looks like for just the first card
save_png range: 0, prefix: 'save_png_'
# save_png supports trim and trim_radius
save_png trim: 30, trim_radius: 38,
range: 0, prefix: 'save_png_trimmed_'
# Place on multiple pages over the PDF, with bleed beeing trimmed off
save_pdf file: 'save-pdf.pdf', margin: 75, gap: 5, trim: 37
# PDFs also support arbitrary paper sizes, in pixels or any other supported units
save_pdf file: 'save-pdf-small.pdf',
width: '7in', height: '5in',
range: 0..1
# Note that our PNGs still are not trimmed even though the pdf ones were
save_png range: 1, prefix: 'saves_notrim_'
# We can also save our PNGs into a single sheet,
# rows are calculated based on cols and number of cards
save_sheet prefix: 'save_single_sheet_',
columns: 2, margin: 75, gap: 5, trim: 37
# Or multiple sheets if rows are also specified
save_sheet prefix: 'save_sheet_',
columns: 4, rows: 2,
margin: 75, gap: 5, trim: 37
# Sheets support ranges too
save_sheet prefix: 'save_sheet_range_',
range: 0..5,
columns: 2, rows: 2,
margin: 75, gap: 5, trim: 37
# Sheets can arrange left-to-right and right-to-left
save_sheet prefix: 'save_sheet_rtl_',
suffix: '_with_suffix',
range: 0..1, rtl: true,
columns: 2, rows: 1,
margin: 75, gap: 5, trim: 37
end
Squib::Deck.new(width: 100, height: 100, cards: 3) do
background color: :grey
text str: 'Hi', font: 'Arial 18'
# Test bug 332.
# When we only have 3 cards but want a 2x4 grid with lots of empty spaces.
# Buggy behavior was to revert to 1 row and not respect the rows arg.
save_sheet prefix: 'save_sheet_bug332_', rows: 2, columns: 4
end
# Allow rotating
Squib::Deck.new(width: 100, height: 50, cards: 8) do
background color: :white
rect x: 10, y: 10, width: 80, height: 30
rect x: 5, y: 5, width: 90, height: 40, stroke_width: 5, stroke_color: :blue
text y: 2, str: 0..7, font: 'Open Sans Bold 8', align: :center, width: 100
save_sheet prefix: 'save_sheet_unrotated_', rows: 2, columns: 3
save_sheet prefix: 'save_sheet_custom_rotate_', rows: 2, columns: 3, rotate: [:clockwise, :counterclockwise] * 4
save_sheet prefix: 'save_sheet_rotated_', rows: 2, columns: 3, rotate: true
save_sheet prefix: 'save_sheet_rotated_trimmed_', rows: 2, columns: 3, rotate: true, trim: 5
save_sheet prefix: 'save_sheet_rotated_trimmed_rtl_', rows: 2, columns: 3, rotate: true, trim: 5, rtl: true
end
|