-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sample data and unit tests #2
Comments
On Wed, Jun 13 2018, scls19fr wrote:
Hello,
It will be great if this project could provide sample data
and use these data as unit tests.
The sample data is available in the tutorial which I'm hosting on
thregr.org, but unfortunately I couldn't get permission to upload it to
github.
|
I haven't found also Gimp template file and exported file |
On Thu, Jun 14 2018, scls19fr wrote:
I haven't found also Gimp template file and exported file template-it.png
Being able to download marks-it.svg could help to follow tutorial more quickly
This is intentional. The files provided are just the scans, which is
exactly what you have when you start from scratch.
Generating all the required files, and doing them properly, is the most
important aspect of the tutorial. It's not intended to be a short
step-by-step overview.
|
ok
|
On Fri, Jun 15 2018, scls19fr wrote:
ok
I have a large form with 25 rows and 5 columns ie 125 questions with 1 possible answer
out of 4 ie 4 check boxes (A, B, C, D).
Do you have a script to generate such svg file?
No, but creating the template with Inkscape is still pretty fast.
Create one rectangle, duplicate it 4 times then assign some template
names, then group, then duplicate it 25 times. Move one down, then
"distribute vertically".
Generating such grids is pretty quick.
Naming them is the slow part, as I'm not aware of a quick way to do this
using Inkscape. In my case, I saved the SVG, did a quick sed script to
rename the values and reloaded it into inkscape for checking.
|
Under Mac OS X and Inkscape 0.92.2, when I copy a rectangle it pastes as image <rect
style="opacity:0.7;fill:#ffb534;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="q4_no"
width="62"
height="62"
x="240"
y="436" />
<image
y="145.87442"
x="121.4196"
id="image4178"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAN1JREFU
eJzt26ENAlEARMGFnEGQKwGPQJDfAA5x1V1CHQi6ogkQhBYYwU4FL+t3syzLK39qjLFOSXI57XM8
7HTPT90ezyTJlCTHwy7X80yDfu07wBZ3cB1AB2gdQAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdo
HUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gd
QAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdoU/L50X6/tP9mGmOsOkKZ5/n+BmkBEBSn2NeOAAAA
AElFTkSuQmCC
"
preserveAspectRatio="none"
height="64"
width="64" /> |
On Fri, Jun 15 2018, scls19fr wrote:
Under Mac OS X and Inkscape 0.92.2, when I copy a rectangle it pastes as image
You have to use "duplicate" (Ctrl+D).
|
Thanks for the tip. Here is my code to create a SVG template with many aligned checkboxes from a png file: #!/usr/bin/env python
import click
import os
import svgwrite
import base64
from PIL import Image
@click.command()
@click.option('--img', default='', help='Image filename')
@click.option('--box-width', default=28.1, help='')
@click.option('--box-height', default=22.6, help='')
@click.option('--offset-x', default=29, help='')
@click.option('--offset-y', default=22, help='')
@click.option('--space-x', default=0, help='')
@click.option('--space-y', default=0, help='')
@click.option('--space-columns', default=143, help='')
@click.option('--rows', default=20, help='')
@click.option('--answers', default=4, help='')
@click.option('--columns', default=5, help='')
@click.option('--color', default='#ffb534', help='')
@click.option('--opacity', default=0.7, help='')
@click.option('--stroke', default='#000000', help='')
@click.option('--stroke-width', default='1px', help='')
def main(img,
box_width, box_height,
offset_x, offset_y,
space_x, space_y, space_columns,
rows, answers, columns,
color, opacity,
stroke, stroke_width):
if space_x == 0:
space_x = box_width
if space_y == 0:
space_y = box_height
# if space_columns == 0:
# space_columns = 10
if img != '':
(img_root, img_ext) = os.path.splitext(img)
allowed_ext = ['.png']
if img_ext not in allowed_ext:
raise NotImplementedError("File extension %r not supported" % img_ext)
filename_out = img_root + '.svg'
else:
filename_out = 'marks.svg'
dwg = svgwrite.Drawing(filename_out, profile='tiny')
if img != '':
with open(img, "rb") as fd_img:
encoded_string = base64.b64encode(fd_img.read())
im = Image.open(img)
img_width, img_height = im.size
im.close()
data = "data:image/png;base64,%s" % encoded_string.decode('ascii')
dwg.add(dwg.image(data, id='image', x=0, y=0, preserveAspectRatio="none", width=im.width, height=im.height))
offset_x_for_col = offset_x
pos_x, pos_y = offset_x, offset_y
for column in range(1, columns + 1):
print("Column: %d" % column)
for row in range(1, rows + 1):
print(" Row: %d" % row)
for answer in range(1, answers + 1):
id = "q_%02d_%02d_%02d" % (column, row, answer)
print(" Answer: %d - %s" % (answer, id))
dwg.add(dwg.rect(insert=(pos_x, pos_y), size=(box_width, box_height),
fill=color, opacity=opacity, id=id,
stroke=stroke, stroke_width=stroke_width)
)
pos_x = pos_x + space_x
pos_x = offset_x_for_col
pos_y = pos_y + space_y
pos_y = offset_y
pos_x += space_columns
offset_x_for_col = pos_x
print("Save to %r" % filename_out)
dwg.save()
if __name__ == '__main__':
main() |
Were you able to get going? |
I don't know if this would be possible, but if you have the chance to share some of the pages to add to the sample data would be nice. |
Hello,
It will be great if this project could provide sample data
and use these data as unit tests.
Kind regards
The text was updated successfully, but these errors were encountered: