示例#1
0
文件: images.py 项目: jimsize/PySolFC
 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
示例#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
示例#3
0
文件: tkutil.py 项目: shlomif/PySolFC
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)
示例#4
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)
示例#5
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
示例#6
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
示例#7
0
文件: tkutil.py 项目: joeraz/PySolFC
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)
示例#8
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)
示例#9
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)
示例#10
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
示例#11
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
示例#12
0
 def __init__(self, file=None, image=None, pil_image_orig=None):
     if file:
         image = Image.open(file).convert('RGBA')
     ImageTk.PhotoImage.__init__(self, image)
     self._pil_image = image
     if pil_image_orig:
         self._pil_image_orig = pil_image_orig
     else:
         self._pil_image_orig = image
示例#13
0
文件: tkutil.py 项目: jimsize/PySolFC
 def __init__(self, file=None, image=None, pil_image_orig=None):
     if file:
         image = Image.open(file).convert('RGBA')
     ImageTk.PhotoImage.__init__(self, image)
     self._pil_image = image
     if pil_image_orig:
         self._pil_image_orig = pil_image_orig
     else:
         self._pil_image_orig = image
示例#14
0
文件: tkutil.py 项目: jimsize/PySolFC
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
示例#15
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
示例#16
0
 def _loadImage(self, name):
     file = os.path.join(self.dir, name)
     image = None
     for ext in IMAGE_EXTENSIONS:
         file = os.path.join(self.dir, name + ext)
         if os.path.isfile(file):
             if Image:
                 image = ImageTk.PhotoImage(Image.open(file))
             else:
                 image = tkinter.PhotoImage(file=file)
             break
     return image
示例#17
0
 def _loadImage(self, name):
     file = os.path.join(self.dir, name)
     image = None
     for ext in IMAGE_EXTENSIONS:
         file = os.path.join(self.dir, name+ext)
         if os.path.isfile(file):
             if Image:
                 image = ImageTk.PhotoImage(Image.open(file))
             else:
                 image = tkinter.PhotoImage(file=file)
             break
     return image
示例#18
0
        def __init__(self, file=None, image=None, pil_image_orig=None):

            if file:
                image = Image.open(file).convert('RGBA')

                basename = os.path.basename(file)
                file_name = os.path.splitext(basename)[0]

                findsum = findfile(file_name)

                if findsum != -3:  # -1 for every check
                    image = masking(image)

                    image.filename = file_name

            ImageTk.PhotoImage.__init__(self, image)
            self._pil_image = image
            if pil_image_orig:
                self._pil_image_orig = pil_image_orig
            else:
                self._pil_image_orig = image
示例#19
0
 def setTile(self, image, stretch=0, save_aspect=0):
     ##print 'setTile:', image, stretch
     if image:
         if Image:
             try:
                 self._bg_img = Image.open(image)
             except:
                 return 0
         else:
             try:
                 self._bg_img = loadImage(file=image, dither=1)
             except:
                 return 0
         self._stretch_bg_image = stretch
         self._save_aspect_bg_image = save_aspect
         self.setBackgroundImage()
     else:
         for id in self.__tiles:
             self.delete(id)
         self.__tiles = []
         self._bg_img = None
     return 1
示例#20
0
 def setTile(self, image, stretch=0, save_aspect=0):
     # print 'setTile:', image, stretch
     if image:
         if Image:
             try:
                 self._bg_img = Image.open(image)
             except:
                 return 0
         else:
             try:
                 self._bg_img = loadImage(file=image, dither=1)
             except:
                 return 0
         self._stretch_bg_image = stretch
         self._save_aspect_bg_image = save_aspect
         self.setBackgroundImage()
     else:
         for id in self.__tiles:
             self.delete(id)
         self.__tiles = []
         self._bg_img = None
     return 1
示例#21
0
 def __init__(self, file=None, image=None):
     if file:
         image = Image.open(file).convert('RGBA')
     ImageTk.PhotoImage.__init__(self, image)
     self._pil_image = image