Example #1
0
 def test_strech(self):
     image = Image("http://test.jpg")
     image.stretch()
     self.assertEqual(
         image.tostring(),
         '<image preserveAspectRatio="none" xlink:href="http://test.jpg" />'
     )
Example #2
0
 def draw_logos(self):
     self.dwg.add(
         Image(get_logo(self.game.away), (ORIGIN_X, ORIGIN_Y - 50),
               (40, 40)))
     self.dwg.add(
         Image(get_logo(self.game.home),
               (ORIGIN_X + ATBAT_W + SEPARATION + ATBAT_W - 40,
                ORIGIN_Y - 50), (40, 40)))
Example #3
0
 def test_fit_horiz(self):
     image = Image("http://test.jpg")
     for align, expected in [('left', 'xMin'), ('center', 'xMid'),
                             ('right', 'xMax')]:
         image.fit(align, 'top', 'meet')
         self.assertEqual(
             image.tostring(),
             '<image preserveAspectRatio="%sYMin meet" xlink:href="http://test.jpg" />'
             % expected)
Example #4
0
 def draw(self, builder):
     pos = builder.position(self.pos[0], builder.y + self.pos[1])
     size = (builder.image_size, builder.image_size)
     image = Image("paper.png", pos, size)
     image.add(Title(self.reference))
     
     obj = Hyperlink(self.link)
     obj.add(image)
     return [obj]
Example #5
0
 def test_fit_vert(self):
     image = Image("http://test.jpg")
     for align, expected in [('top', 'YMin'), ('middle', 'YMid'),
                             ('bottom', 'YMax')]:
         image.fit('left', align, 'slice')
         self.assertEqual(
             image.tostring(),
             '<image preserveAspectRatio="xMin%s slice" xlink:href="http://test.jpg" />'
             % expected)
Example #6
0
 def draw(self, builder):
     pos = builder.position(self.pos[0], builder.y + self.pos[1])
     size = (builder.image_size, builder.image_size)
     result = []
     title = self.name
     if self.email:
         title += " <{}>".format(self.email)
     color = builder.authors[self.email, "rgb(128, 128, 128)"]
     
     result.append(Rect(pos, size, fill=color, stroke=color, stroke_width=10))
     result.append(Rect(pos, size, fill=WHITE, stroke=WHITE, stroke_width=5))
     image = Image(self.image, pos, size)
     image.add(Title(title))
     result.append(image)
     return result
Example #7
0
def prepare_character_images(drawing):
    # Load images base64 encoded to embed into svg file
    character_images = dict()

    for index in range(0, 84):
        p = Pattern(x=0,
                    y=0,
                    width="100%",
                    height="100%",
                    viewBox="0 0 512 512")
        image_path = ROOT_PATH_IMAGES + str(index) + ".jpeg"

        # Loading the image an convert it to base64 to integrate it directly
        # into the graphic.
        base64_prefix_href = "data:image/jpeg;base64,"
        with open(image_path, 'rb') as image:
            base64_encoded_string = base64.standard_b64encode(image.read())
        href_base64_img = base64_prefix_href + base64_encoded_string.decode(
            'utf-8')

        i = Image(href=href_base64_img, x="0%", y="0%", width=512, height=512)
        p.add(i)
        drawing.defs.add(p)
        character_images[index] = p

    return character_images
Example #8
0
def member_badge(stripe_id):

    svg_document = svgwrite.Drawing(size = ("3.375in", "2.125in"))

    logo = Image(href="/static/images/syn_shop_badge_logo.png", insert=("0.5in",'0.5in'), size=("1in","1in"))
    svg_document.add(logo)

    photo_url = "/member/%s/files/photo.jpg" % (stripe_id,)
    photo = Image(href=photo_url,insert=("1.5in",'1.5in'),size=("1in","1in"))
    svg_document.add(photo)

    #svg_document.add(svg_document.text("Hello World",insert = ("1in","1in")))

    response = make_response(svg_document.tostring())
    response.headers['Content-Description'] = 'Badge'
    response.headers['Cache-Control'] = 'no-cache'
    response.headers['Content-Type'] = 'image/svg+xml'
    response.headers['Content-Disposition'] = 'inline'

    return response
        if mod > 0:
            x = x + BOX_SPACING[0]
        else:
            y = y + BOX_SPACING[1]
            x = ORIGIN[0]
    group = dwg.add(dwg.g(id=i))
    group.add(
        dwg.rect(insert=(x * cm, y * cm),
                 size=(BOX_SIZE[0] * cm, BOX_SIZE[1] * cm),
                 stroke='red',
                 fill='white'))
    image_x = x + IMAGE_OFFSET[0]
    image_y = y + IMAGE_OFFSET[1]
    group.add(
        Image("images/" + d['company'].lower() + ".png",
              insert=(image_x * cm, image_y * cm),
              size=(IMAGE_SIZE[0] * cm, IMAGE_SIZE[1] * cm)))

    logo_x = x + LOGO_OFFSET[0]
    logo_y = y + LOGO_OFFSET[1]
    group.add(
        Image("images/athleta_logo_260x180.png",
              insert=(logo_x * cm, logo_y * cm),
              size=(LOGO_SIZE[0] * cm, LOGO_SIZE[1] * cm)))

    text1_x = x + TEXT1_OFFSET[0]
    text1_y = y + TEXT1_OFFSET[1]
    group.add(
        svgwrite.text.Text(d['sf'].upper(), (text1_x * cm, text1_y * cm),
                           class_="text_style",
                           id="text1"))
Example #10
0
 def test_fit_err(self):
     image = Image("http://test.jpg")
     self.assertRaises(ValueError, image.fit, scale='invalid')
     self.assertRaises(KeyError, image.fit, horiz='invalid')
     self.assertRaises(KeyError, image.fit, vert='invalid')
Example #11
0
 def test_constructor2(self):
     image = Image("test.jpg", insert=(10, 20), size=(30, 40))
     self.assertEqual(
         image.tostring(),
         '<image height="40" width="30" x="10" xlink:href="test.jpg" y="20" />'
     )
Example #12
0
 def test_constructor(self):
     image = Image("http://localhost/test.jpg")
     self.assertEqual(image.tostring(), '<image xlink:href="http://localhost/test.jpg" />')
Example #13
0
 def test_constructor(self):
     image = Image("http://localhost/test.jpg")
     self.assertEqual(image.tostring(),
                      '<image xlink:href="http://localhost/test.jpg" />')
Example #14
0
 def test_fit_vert(self):
     image = Image("http://test.jpg")
     for align, expected in [('top', 'YMin'), ('middle', 'YMid'), ('bottom', 'YMax')]:
         image.fit('left', align, 'slice')
         self.assertEqual(image.tostring(), '<image preserveAspectRatio="xMin%s slice" xlink:href="http://test.jpg" />' % expected)
Example #15
0
 def test_fit_horiz(self):
     image = Image("http://test.jpg")
     for align, expected in [('left', 'xMin'), ('center', 'xMid'), ('right', 'xMax')]:
         image.fit(align, 'top', 'meet')
         self.assertEqual(image.tostring(), '<image preserveAspectRatio="%sYMin meet" xlink:href="http://test.jpg" />' % expected)
Example #16
0
 def test_strech(self):
     image = Image("http://test.jpg")
     image.stretch()
     self.assertEqual(image.tostring(), '<image preserveAspectRatio="none" xlink:href="http://test.jpg" />')
Example #17
0
 def test_constructor2(self):
     image = Image("test.jpg", insert=(10,20), size=(30,40))
     self.assertEqual(image.tostring(), '<image height="40" width="30" x="10" xlink:href="test.jpg" y="20" />')