Example #1
0
 def getShadowPIL(self, stack, cards):
     x0, y0 = stack.getPositionFor(cards[0])
     x1, y1 = stack.getPositionFor(cards[-1])
     x0, x1 = min(x1, x0), max(x1, x0)
     y0, y1 = min(y1, y0), max(y1, y0)
     cw, ch = self.getSize()
     x1 += cw
     y1 += ch
     w, h = x1 - x0, y1 - y0
     if (w, h) in self._pil_shadow:
         return self._pil_shadow[(w, h)]
     # create mask
     mask = Image.new('RGBA', (w, h))
     for c in cards:
         x, y = stack.getPositionFor(c)
         x, y = x - x0, y - y0
         im = c._active_image._pil_image
         mask.paste(im, (x, y), im)
     # create shadow
     sh_color = (0x00, 0x00, 0x00, 0x50)
     shadow = Image.new('RGBA', (w, h))
     shadow.paste(sh_color, (0, 0, w, h), mask)
     sx, sy = self.SHADOW_XOFFSET, self.SHADOW_YOFFSET
     mask = mask.crop((sx, sy, w, h))
     tmp = Image.new('RGBA', (w - sx, h - sy))
     shadow.paste(tmp, (0, 0), mask)
     shadow = ImageTk.PhotoImage(shadow)
     self._pil_shadow[(w, h)] = shadow
     return shadow
Example #2
0
 def getShadowPIL(self, stack, cards):
     x0, y0 = stack.getPositionFor(cards[0])
     x1, y1 = stack.getPositionFor(cards[-1])
     x0, x1 = min(x1, x0), max(x1, x0)
     y0, y1 = min(y1, y0), max(y1, y0)
     cw, ch = self.getSize()
     x1 += cw
     y1 += ch
     w, h = x1-x0, y1-y0
     if (w, h) in self._pil_shadow:
         return self._pil_shadow[(w, h)]
     # create mask
     mask = Image.new('RGBA', (w, h))
     for c in cards:
         x, y = stack.getPositionFor(c)
         x, y = x-x0, y-y0
         im = c._active_image._pil_image
         mask.paste(im, (x, y), im)
     # create shadow
     sh_color = (0x00, 0x00, 0x00, 0x50)
     shadow = Image.new('RGBA', (w, h))
     shadow.paste(sh_color, (0, 0, w, h), mask)
     sx, sy = self.SHADOW_XOFFSET, self.SHADOW_YOFFSET
     mask = mask.crop((sx, sy, w, h))
     tmp = Image.new('RGBA', (w-sx, h-sy))
     shadow.paste(tmp, (0, 0), mask)
     shadow = ImageTk.PhotoImage(shadow)
     self._pil_shadow[(w, h)] = shadow
     return shadow
Example #3
0
def createImagePIL(width, height, fill, outline=None):
    if not fill:
        image = Image.new('RGBA', (width, height))
    else:
        image = Image.new('RGBA', (width, height), color=fill)
    if outline is not None:
        draw = ImageDraw.Draw(image)
        draw.rectangle([0, 0, width - 1, height - 1],
                       fill=None,
                       outline=outline,
                       width=1)

    return PIL_Image(image=image)
Example #4
0
def shadowImage(image, color='#3896f8', factor=0.3):
    if not hasattr(image, '_pil_image'):
        return None
    im = image._pil_image
    if Image.VERSION >= '1.1.7':
        # use an alpha image
        sh = Image.new('RGBA', im.size, color)
        sh.putalpha(100)
        out = Image.composite(sh, im, im)
        return PIL_Image(image=out)
    sh = Image.new('RGBA', im.size, color)
    tmp = Image.blend(im, sh, factor)
    out = Image.composite(tmp, im, im)
    return PIL_Image(image=out)
def shadowImage(image, color='#3896f8', factor=0.3):
    if not hasattr(image, '_pil_image'):
        return None
    im = image._pil_image
    if Image.VERSION >= '1.1.7':
        # use an alpha image
        sh = Image.new('RGBA', im.size, color)
        sh.putalpha(100)
        out = Image.composite(sh, im, im)
        return PIL_Image(image=out)
    sh = Image.new('RGBA', im.size, color)
    tmp = Image.blend(im, sh, factor)
    out = Image.composite(tmp, im, im)
    return PIL_Image(image=out)
Example #6
0
def shadowImage(image, color='#3896f8', factor=0.3):
    if not hasattr(image, '_pil_image'):
        return None
    im = image._pil_image
    # use an alpha image
    sh = Image.new('RGBA', im.size, color)
    sh.putalpha(100)
    out = Image.composite(sh, im, im)
    return PIL_Image(image=out)
Example #7
0
def shadowImage(image, color='#3896f8', factor=0.3):
    if not hasattr(image, '_pil_image'):
        return None
    im = image._pil_image
    # use an alpha image
    sh = Image.new('RGBA', im.size, color)
    sh.putalpha(100)
    out = Image.composite(sh, im, im)
    return PIL_Image(image=out)
Example #8
0
def markImage(image):
    assert Image
    if 1:                               # shadow
        color, factor = '#6ae400', 0.3
        sh = Image.new('RGBA', image.size, color)
        tmp = Image.blend(image, sh, factor)
    else:                               # negate
        tmp = ImageOps.invert(image.convert('RGB'))
    out = Image.composite(tmp, image, image)
    return out
Example #9
0
def markImage(image):
    assert Image
    if 1:  # shadow
        color, factor = '#6ae400', 0.3
        sh = Image.new('RGBA', image.size, color)
        tmp = Image.blend(image, sh, factor)
    else:  # negate
        tmp = ImageOps.invert(image.convert('RGB'))
    out = Image.composite(tmp, image, image)
    return out
Example #10
0
def _createBottomImage(image, color='white', backfile=None):
    th = 1                              # thickness
    sh = Image.new('RGBA', image.size, color)
    out = Image.composite(sh, image, image)
    w, h = image.size
    size = (w-th*2, h-th*2)
    tmp = Image.new('RGBA', size, color)
    tmp.putalpha(60)
    mask = out.resize(size, Image.ANTIALIAS)
    out.paste(tmp, (th, th), mask)
    if backfile:
        back = Image.open(backfile).convert('RGBA')
        w0, h0 = back.size
        w1, h1 = w, h
        a = min(float(w1)/w0, float(h1)/h0)
        a = a*0.9
        w0, h0 = int(w0*a), int(h0*a)
        back = back.resize((w0, h0), Image.ANTIALIAS)
        x, y = (w1 - w0) // 2, (h1 - h0) // 2
        out.paste(back, (x, y), back)
    return out
Example #11
0
def _createBottomImage(image, color='white', backfile=None):
    th = 1  # thickness
    sh = Image.new('RGBA', image.size, color)
    out = Image.composite(sh, image, image)
    w, h = image.size
    size = (w - th * 2, h - th * 2)
    tmp = Image.new('RGBA', size, color)
    tmp.putalpha(60)
    mask = out.resize(size, Image.ANTIALIAS)
    out.paste(tmp, (th, th), mask)
    if backfile:
        back = Image.open(backfile).convert('RGBA')
        w0, h0 = back.size
        w1, h1 = w, h
        a = min(float(w1) / w0, float(h1) / h0)
        a = a * 0.9
        w0, h0 = int(w0 * a), int(h0 * a)
        back = back.resize((w0, h0), Image.ANTIALIAS)
        x, y = (w1 - w0) // 2, (h1 - h0) // 2
        out.paste(back, (x, y), back)
    return out
Example #12
0
 def _createDisabledButtonImage(self, tkim):
     # grayscale and light-up image
     if not tkim:
         return None
     im = tkim._pil_image
     dis_im = ImageOps.grayscale(im)
     ##color = '#ffffff'
     ##factor = 0.6
     color = '#dedede'
     factor = 0.7
     sh = Image.new(dis_im.mode, dis_im.size, color)
     tmp = Image.blend(dis_im, sh, factor)
     dis_im = Image.composite(tmp, im, im)
     dis_tkim = ImageTk.PhotoImage(image=dis_im)
     return dis_tkim
Example #13
0
 def _createDisabledButtonImage(self, tkim):
     # grayscale and light-up image
     if not tkim:
         return None
     im = tkim._pil_image
     dis_im = ImageOps.grayscale(im)
     # color = '#ffffff'
     # factor = 0.6
     color = '#dedede'
     factor = 0.7
     sh = Image.new(dis_im.mode, dis_im.size, color)
     tmp = Image.blend(dis_im, sh, factor)
     dis_im = Image.composite(tmp, im, im)
     dis_tkim = ImageTk.PhotoImage(image=dis_im)
     return dis_tkim