当前位置: 首页>>代码示例>>Python>>正文


Python Image.new方法代码示例

本文整理汇总了Python中Image.new方法的典型用法代码示例。如果您正苦于以下问题:Python Image.new方法的具体用法?Python Image.new怎么用?Python Image.new使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_image

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def new_image(self, **kwargs):
        back_color = kwargs.get("back_color", "white")
        fill_color = kwargs.get("fill_color", "black")

        if fill_color.lower() != "black" or back_color.lower() != "white":
            if back_color.lower() == "transparent":
                mode = "RGBA"
                back_color = None
            else:
                mode = "RGB"
        else:
            mode = "1"
            # L mode (1 mode) color = (r*299 + g*587 + b*114)//1000
            if fill_color.lower() == "black": fill_color = 0
            if back_color.lower() == "white": back_color = 255

        img = Image.new(mode, (self.pixel_size, self.pixel_size), back_color)
        self.fill_color = fill_color
        self._idr = ImageDraw.Draw(img)
        return img 
开发者ID:tp4a,项目名称:teleport,代码行数:22,代码来源:pil.py

示例2: render_simple_gauge

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def render_simple_gauge(self, value=None, major_ticks=None, minor_ticks=None, label=None, font=None):
        """Helper function to create gauges with minimal code, eg:

            import Image
            import gauges

            im = Image.new("RGB", (200, 200), (255, 255, 255))
            g = gauges.GaugeDraw(im, 0, 100)
            g.render_simple_gauge(value=25, major_ticks=10, minor_ticks=2, label="25")
            im.save("simple_gauge_image.png", "PNG")

        Does not support dial labels, histogram dial background or setting colors..
        """
        if value is not None:
            self.add_needle(value)

        if major_ticks is not None:
            self.add_dial(major_ticks, minor_ticks, dial_font=font)

        if label is not None:
            self.add_text(text_list=label, text_font=font)

        self.render() 
开发者ID:songyanho,项目名称:Reinforcement-Learning-for-Self-Driving-Cars,代码行数:25,代码来源:gauge.py

示例3: create_sample

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def create_sample(colors, f=os.path.join(WALL_DIR, ".tmp.sample.png")):
    im = Image.new("RGB", (480, 50), "white")
    pix = im.load()
    width_sample = im.size[0]//(len(colors)//2)

    for i, c in enumerate(colors[:8]):
        for j in range(width_sample*i, width_sample*i+width_sample):
            for k in range(0, 25):
                pix[j, k] = pywal.util.hex_to_rgb(c)

    for i, c in enumerate(colors[8:16]):
        for j in range(width_sample*i, width_sample*i+width_sample):
            for k in range(25, 50):
                pix[j, k] = pywal.util.hex_to_rgb(c)

    im.save(f) 
开发者ID:deviantfero,项目名称:wpgtk,代码行数:18,代码来源:sample.py

示例4: show

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def show(self, img_x=1350, img_y=20, dry_run=False):
        """
        show image representing the interval
        """
        try:
            import Image
            import ImageDraw
        except ImportError:
            print('cannot import python PIL imaging')
            return

        img = Image.new('RGB', (img_x, img_y), (100, 100, 100))
        draw = ImageDraw.Draw(img)
        i_min, i_max = self.hull()

        print(hex(i_min), hex(i_max))

        addr2x = lambda addr: ((addr - i_min) * img_x) // (i_max - i_min)
        for a, b in self.intervals:
            draw.rectangle((addr2x(a), 0, addr2x(b), img_y), (200, 0, 0))

        if dry_run is False:
            img.show() 
开发者ID:cea-sec,项目名称:miasm,代码行数:25,代码来源:interval.py

示例5: invert

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def invert(image):
    "Invert a channel"

    image.load()
    return image._new(image.im.chop_invert())

##
# Compare images, and return lighter pixel value
# (max(image1, image2)).
# <p>
# Compares the two images, pixel by pixel, and returns a new image
# containing the lighter values.
#
# @param image1 First image.
# @param image1 Second image.
# @return An image object. 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:18,代码来源:ImageChops.py

示例6: __fixup

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def __fixup(self, im1):
        # convert image to suitable mode
        if isinstance(im1, _Operand):
            # argument was an image.
            if im1.im.mode in ("1", "L"):
                return im1.im.convert("I")
            elif im1.im.mode in ("I", "F"):
                return im1.im
            else:
                raise ValueError, "unsupported mode: %s" % im1.im.mode
        else:
            # argument was a constant
            if _isconstant(im1) and self.im.mode in ("1", "L", "I"):
                return Image.new("I", self.im.size, im1)
            else:
                return Image.new("F", self.im.size, im1) 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:18,代码来源:ImageMath.py

示例7: move

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def move(self, src, dst, name):
        """
        Move file. Return new file path or raise an Exception.
        """

        stat = self.stat(src)
        
        if not stat['read'] or (stat['mime'] == 'directory' and self.command_disabled('rmdir')):
            raise PermissionDeniedError

        stat['realpath'] = src
        self._rm_tmb(stat) #can not do rmTmb() after _move()
        
        try:
            self._move(src, dst, name)
        except:
            raise NamedError(ElfinderErrorMessages.ERROR_MOVE, self._path(src))
        
        self._clear_cached_dir(self._dirname(src))
        self._clear_cached_stat(src)
        self._clear_cached_dir(dst)
        self._removed.append(stat)
        
        return self._join_path(dst, name) 
开发者ID:guohongze,项目名称:adminset,代码行数:26,代码来源:base.py

示例8: _img_square_fit

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def _img_square_fit(self, im, target, width, height, bgcolor = '#ffffff', destformat = None):
        """
        Put image to square
        """

        bg = Image.new('RGB', (width, height), bgcolor)

        if im.mode == 'RGBA':
            bg.paste(im, ((width-im.size[0])/2, (height-im.size[1])/2), im)
        else: #do not use a mask if file is not in RGBA mode.
            bg.paste(im, ((width-im.size[0])/2, (height-im.size[1])/2))

        if target:
            self._saveimage(bg, target, destformat if destformat else im.format)

        return bg 
开发者ID:guohongze,项目名称:adminset,代码行数:18,代码来源:base.py

示例9: _unique_name

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def _unique_name(self, dir_, name, suffix = ' copy', check_num=True):
        """
        Return new unique name based on file name and suffix
        """
        
        ext  = ''
        m = re.search(r'\.((tar\.(gz|bz|bz2|z|lzo))|cpio\.gz|ps\.gz|xcf\.(gz|bz2)|[a-z0-9]{1,4})$', name, re.IGNORECASE)
        if m:
            ext  = '.%s' % m.group(1)
            name = name[0:len(name)-len(m.group(0))] 
        
        m = re.search('(%s)(\d*)$' % suffix, name, re.IGNORECASE)
        if check_num and m and m.group(2):
            i = int(m.group(2))
            name = name[0:len(name)-len(m.group(2))]
        else:
            i = 1
            name += suffix

        return self._get_available_name(dir_, name, ext, i) 
开发者ID:guohongze,项目名称:adminset,代码行数:22,代码来源:base.py

示例10: _pilbitmap_check

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def _pilbitmap_check():
    global _pilbitmap_ok
    if _pilbitmap_ok is None:
        try:
            im = Image.new("1", (1,1))
            Tkinter.BitmapImage(data="PIL:%d" % im.im.id)
            _pilbitmap_ok = 1
        except Tkinter.TclError:
            _pilbitmap_ok = 0
    return _pilbitmap_ok

# --------------------------------------------------------------------
# PhotoImage

##
# Creates a Tkinter-compatible photo image.  This can be used
# everywhere Tkinter expects an image object.  If the image is an RGBA
# image, pixels having alpha 0 are treated as transparent. 
开发者ID:cineuse,项目名称:CNCGToolKit,代码行数:20,代码来源:ImageTk.py

示例11: lighter

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def lighter(image1, image2):
    "Select the lighter pixels from each image"

    image1.load()
    image2.load()
    return image1._new(image1.im.chop_lighter(image2.im))

##
# Compare images, and return darker pixel value
# (min(image1, image2)).
# <p>
# Compares the two images, pixel by pixel, and returns a new image
# containing the darker values.
#
# @param image1 First image.
# @param image1 Second image.
# @return An image object. 
开发者ID:cineuse,项目名称:CNCGToolKit,代码行数:19,代码来源:ImageChops.py

示例12: encode

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def encode(font, c):
    im = Image.new("L", (128, 160))
    dr = ImageDraw.Draw(im)
    dr.text((10,40), c, font=font1, fill=255)
    # print im.getbbox()
    im = im.crop((10, 44, 16, 51))
    (w,h) = im.size
    nyb = (np.array(im).flatten() * 10 / 255).tolist()
    return nyb

    print c, "".join(["%x" % x for x in nyb])
    saved = 0
    for i in range(len(nyb)):
        if nyb[i:i+3] == [0,0,0]:
            saved += 1
    # print c, "saved", saved
    return len(nyb) - saved 
开发者ID:jamesbowman,项目名称:spidriver,代码行数:19,代码来源:mkfont.py

示例13: main

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def main():
    epd = epd7in5b.EPD()
    epd.init()

    # For simplicity, the arguments are explicit numerical coordinates
    # image_red = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255)    # 255: clear the frame
    # draw_red = ImageDraw.Draw(image_red)
    # image_black = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255)    # 255: clear the frame
    # draw_black = ImageDraw.Draw(image_black)
    # font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24)
    # draw_red.rectangle((0, 6, 640, 40), fill = 0)
    # draw_red.text((200, 10), 'e-Paper demo', font = font, fill = 255)
    # draw_red.rectangle((200, 80, 600, 280), fill = 0)
    # draw_red.chord((240, 120, 580, 220), 0, 360, fill = 255)
    # draw_black.rectangle((20, 80, 160, 280), fill = 0)
    # draw_red.chord((40, 80, 180, 220), 0, 360, fill = 0)
    # epd.display_frame(epd.get_frame_buffer(image_black),epd.get_frame_buffer(image_red))

    # display images
    frame_black = epd.get_frame_buffer(Image.open('black.png'))
    frame_red = epd.get_frame_buffer(Image.open('white.png'))
    epd.display_frame(frame_black, frame_red) 
开发者ID:BenRoe,项目名称:rpi-magicmirror-eink,代码行数:24,代码来源:main.py

示例14: _createCanvas

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def _createCanvas(size):
    useAGG, useCairo, Canvas = _getCanvas()
    if useAGG or useCairo:
        try:
            import Image
        except ImportError:
            from PIL import Image
        img = Image.new("RGBA", size, (0, 0, 0, 0))
        canvas = Canvas(img)
    else:
        from rdkit.Chem.Draw.spingCanvas import Canvas
        canvas = Canvas(size=size, name='MolToImageFile')
        img = canvas._image
    return img, canvas 
开发者ID:blackmints,项目名称:3DGCN,代码行数:16,代码来源:__init__.py

示例15: MolsToImage

# 需要导入模块: import Image [as 别名]
# 或者: from Image import new [as 别名]
def MolsToImage(mols, subImgSize=(200, 200), legends=None, **kwargs):
    """
    """
    try:
        import Image
    except ImportError:
        from PIL import Image
    if legends is None:
        legends = [None] * len(mols)
    res = Image.new("RGBA", (subImgSize[0] * len(mols), subImgSize[1]))
    for i, mol in enumerate(mols):
        res.paste(MolToImage(mol, subImgSize, legend=legends[i], **kwargs), (i * subImgSize[0], 0))
    return res 
开发者ID:blackmints,项目名称:3DGCN,代码行数:15,代码来源:__init__.py


注:本文中的Image.new方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。