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


Python Image.close方法代码示例

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


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

示例1: compose_image_slide

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
    def compose_image_slide(self, image_path=None, text=None, slide_id=1):

        image_display_size = (300, 190)

        key = '%s-%s-%03d' % (self.emission.uuid, self.content_object.uuid, slide_id)
        path = os.path.join(SLIDE_BASE_DIR, key + '.{}'.format(IMAGE_OUTPUT_FORMAT))
        url = SLIDE_BASE_URL + key + '.{}'.format(IMAGE_OUTPUT_FORMAT)

        overlay_image = Image(filename=image_path)

        with Drawing() as draw:

            size = overlay_image.size

            if size[0] > size[1]:
                orientation = 'landscape'
                scale = float(image_display_size[1]) / float(size[1])
            else:
                orientation = 'portrait'
                scale = float(image_display_size[1]) / float(size[0])

            overlay_image.resize(int(size[0] * scale), int(size[1] * scale))

            #size = overlay_image.size

            width = 190
            height = 190
            overlay_image.crop(10, 0, width=width, height=height)

            draw.composite('over', left=int(width / 2) - 20, top=10, width=width, height=height, image=overlay_image)

            # text settings
            draw.font = SLIDE_BASE_FONT
            draw.font_size = 14
            draw.text_interline_spacing = 8
            draw.fill_color = Color('white')
            draw.text_antialias = True

            # draw text
            if text:
                draw.text(220, 10, text)

            # compose image
            with Image(filename=SLIDE_BASE_IMAGE) as image:
                draw(image)

                if IMAGE_OUTPUT_FORMAT == 'jpg':
                    image.compression_quality = 62
                    image.format = 'jpeg'

                image.save(filename=path)
                image.save(filename=os.path.join(SLIDE_BASE_DIR, 'debug-{}.{}'.format(slide_id, IMAGE_OUTPUT_FORMAT)))

        try:
            overlay_image.close()
        except Exception as e:
            # TODO: use narrowed exception(s)
            log.warning('unable to close magick/wand overlay image - {}'.format(e))

        return url
开发者ID:hzlf,项目名称:openbroadcast.org,代码行数:62,代码来源:generator.py

示例2: scale

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
def scale(imagePath, face):
  # cloneImg.save(filename='{0}-{1}.jpg'.format(imagePath, i))

  face_x, face_y, face_w, face_h = face

  with Image(filename=imagePath) as img:
    img_w = img.size[0]
    img_h = img.size[1]

    w_delta = ((img_w - face_w) / 2) / NUM_IMAGES
    h_delta = ((img_h - face_h) / 2) / NUM_IMAGES

    gifImg = Image()

    for i in range(NUM_IMAGES, -1, -1):
      with img.clone() as cloneImg:
        if i == 0:
          cloneImg.crop(face_x, face_y, width=face_w, height=face_h)
          cloneImg.transform(resize='%dx%d' % (img_w, img_h))
        else:
          left = max(0, face_x - i * w_delta)
          top = max(0, face_y - i * h_delta)
          right = min(img_w, face_x + face_w + i * w_delta)
          bottom = min(img_h, face_y + face_h + i * h_delta)

          cloneImg.crop(left, top, right, bottom)
          cloneImg.transform(resize='%dx%d' % (img_w, img_h))
        gifImg.sequence.append(cloneImg)

    for frame in gifImg.sequence:
      with frame:
        frame.delay = 20
    gifImg.save(filename='%s.gif' % imagePath)
    gifImg.close()
    return '%s.gif' % imagePath
开发者ID:karan,项目名称:slashZoomEnhance,代码行数:37,代码来源:face_detect.py

示例3: series_to_animated_gif

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
def series_to_animated_gif(L, filepath):
    imgs = Image(filename=L[0])
    for i in L[1:]:
        im2 = Image(filename=i)
        imgs.sequence.append(im2)
        for i in imgs.sequence:
            i.delay = 25
    imgs.save(filename=filepath)
    imgs.close()
    print('saved animated.gif')
开发者ID:ultimateboy,项目名称:beanbot,代码行数:12,代码来源:tasks.py

示例4: compose

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
def compose(conn, ready_queue, images, config):
    from wand.image import Image
    from wand.color import Color
    import os

    # get all the images and overlay them
    layers = []
    while len(layers) < images:
        try:
            this_config = ready_queue.get()
            layers.append((this_config['name'], this_config))
        except Queue.Empty:
            pass

    # the base to the image we are producing
    base = Image(width=config['width'],
                 height=config['height'],
                 background=Color(config['background']))

    cache = {}

    for name, image_config in sorted(layers):
        x, y, w, h = image_config['area']
        print name, x, y, w, h
        try:
            temp_image = cache[image_config['filename']]
        except KeyError:
            temp_image = Image(filename=image_config['filename'])
            cache[image_config['filename']] = temp_image
        base.composite(temp_image, x, y)

    # save it!
    new_path = 'composite.png'

    for image in cache.values():
        image.close()

    # append a dash and numberal if there is a duplicate
    if os.path.exists(new_path):
        i = 1
        root, ext = os.path.splitext(new_path)
        new_path = "{0}-{1:04d}{2}".format(root, i, ext)
        while os.path.exists(new_path):
            i += 1
            new_path = "{0}-{1:04d}{2}".format(root, i, ext)

    base.format = 'png'
    base.save(filename=new_path)
    base.close()

    conn.send(new_path)
    conn.close()
开发者ID:ikol,项目名称:PURIKURA,代码行数:54,代码来源:composer.py

示例5: combine_layers

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
def combine_layers(images, filename):
    combo = None
    for index, im in enumerate(images):
        if not isinstance(combo, Image):
            combo = Image(filename=im)
        if index == len(images) - 1:
            break
        else:
            im2 = images[index + 1]
            im2 = Image(filename=im2)
            combo.composite(im2, left=0, top=0)
    combo.save(filename=filename)
    combo.close()
开发者ID:cedrikv,项目名称:static_map_generator,代码行数:15,代码来源:utils.py

示例6: ImageHandler

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
class ImageHandler(BaseHandler):
    pil_formats = ['jpg', 'jpeg', 'png', 'eps']
    magick_formats = ['psd', 'ai']

    def __init__(self, filename, file_type):
        self.local_file = filename
        self.file_type = file_type
        try:
            if file_type not in self.magick_formats:
                self.im = PILImage.open(filename)
                if self.im.mode == 'P':
                    self.im = self.im.convert('RGBA')
                self.size = self.im.size
                self.format = self.im.format
                self.width = self.im.width
                self.height = self.im.height
            else:
                self.im = WandImage(filename=filename+'[0]')
                self.format = file_type
                self.size = self.im.size
                self.width = self.im.width
                self.height = self.im.height
        except Exception as e:
            print e

    def is_smaller(self):
        if self.file_type in self.magick_formats:
            return False
        size = self.size
        width = size[0]
        height = size[1]
        return (width < 200) and (height < 200)

    def get_metadata(self):
        with exiftool.ExifTool() as et:
            metadata = et.get_metadata(self.local_file)
        return metadata

    def thumbnail(self, thumb_filename):
        if self.file_type in self.magick_formats:
            self.im.transform(resize=thumbnail_size)
            self.im.save(filename=thumb_filename)
        else:
            self.im.thumbnail((200, 200), PILImage.ANTIALIAS)
            self.im.save(thumb_filename, 'JPEG')

    def close(self):
        if self.file_type not in self.magick_formats:
            self.im.close()
开发者ID:InBetween,项目名称:AssetManager,代码行数:51,代码来源:assetHandler.py

示例7: main

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
def main():
    args = parseArguments()

    px = args.pixels
    out = args.out
    filename_out = os.path.splitext(ntpath.basename(args.input))[0] + ".png"

    img = Image(filename=args.input, resolution=(72, 72))
    img.clone().convert('png').save(filename="xxx.png")
    if args.mode is 'android' or args.mode is 'all':
        convertImage(img, px,       join(out, "drawable-mdpi"), filename_out)
        convertImage(img, int(px * 1.5), join(out, "drawable-hdpi"), filename_out)
        convertImage(img, px * 2,   join(out, "drawable-xhdpi"), filename_out)
        convertImage(img, px * 3,   join(out, "drawable-xxhdpi"), filename_out)
        convertImage(img, px * 4,   join(out, "drawable-xxxhdpi"), filename_out)
    elif args.mode is 'ios' or args.mode is 'all':
        convertImage(img, px * 2,   join(out, "ios-2x"), filename_out)
        convertImage(img, px,       join(out, "ios-1x"), filename_out)
        convertImage(img, px * 3,   join(out, "ios-3x"), filename_out)
    img.close()
开发者ID:git-commit,项目名称:vector2android,代码行数:22,代码来源:vector2android.py

示例8: opImplement

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
 def opImplement(self):
     self.takeScreenShort();
     try:
         from wand.image import Image
         from wand.color import Color
         gifSeq = Image();
         index=0;
         
         for index,file in enumerate(self.seq):
             with Image(filename=file) as seq:
                 gifSeq.sequence.append(seq);
                 #We add something in s/100 secound.
                 gifSeq.sequence[index].delay = self.delay;
                 #After changing delay that must be call this function
                 gifSeq.sequence[index].destroy();
         gifSeq.save(filename=self.gif);
         gifSeq.close();
     except:
         raise;
     finally:
         import os;
         for file in self.seq:
             os.remove(file);
     return self.data;
开发者ID:avontd2868,项目名称:OU_Final_Year,代码行数:26,代码来源:vtkOperations.py

示例9: main

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
def main():
	args = get_args()

	draw = Drawing()
	draw.font = args.font_file
	draw.font_size = args.font_size

	font_name = args.font_name
	out_dir = args.out_dir

	img_ref = Image(width=1000, height=1000)

	if args.verbose:
		print "Writing " + out_dir + "/" + font_name + ".c"
	f = open(out_dir + "/" + font_name + ".c", 'wb+')
	write_comment(f)
	f.write("#include \"font.h\"\n\n")

	font_height = 0
	range_first = 0x20
	range_last = 0x7d
	font_width = []
	max_width = 0
	for x in range(range_first, range_last + 1):
		letter = chr(x)
		metrics = draw.get_font_metrics(img_ref, letter)
		text_height = int(round(metrics.text_height + 2))
		if font_height == 0:
			font_height = text_height
		assert (font_height == text_height), "font height changed!"
		if max_width == 0:
			max_width = metrics.maximum_horizontal_advance + 2
		assert (max_width == metrics.maximum_horizontal_advance + 2), \
			"font advance width changed!"
		text_width = int(round(metrics.text_width + 2))
		font_width.append(text_width)
		img = Image(width=text_width, height=text_height)
		d = draw.clone()
		d.text(0, int(metrics.ascender), letter)
		d(img)

		img.depth = 1;

		f.write("static const unsigned char ")
		f.write("letter_" + str(hex(x)[2:]) + "[] = {\n")
		c_hex_print(f, img.make_blob(format='A'))
		f.write("};\n\n")
		img.close()

	f.write("static const struct font_letter letters[] = {\n")
	for x in range(range_first, range_last + 1):
		letter_var_name = "letter_" + str(hex(x)[2:])
		f.write("\t{ " + letter_var_name + ", ")
		f.write("sizeof(" + letter_var_name + "), ")
		f.write(str(font_width[x - range_first]) + "},\n")
	f.write("};\n\n")

	f.write("const struct font font_" + font_name + " = {\n")
	f.write("\t.first = " + str(hex(range_first)) + ",\n")
	f.write("\t.last = " + str(hex(range_last)) + ",\n")
	f.write("\t.letters = letters,\n")
	f.write("\t.height = " + str(font_height) + ",\n")
	f.write("\t.max_width = " + str(max_width) + ",\n")
	f.write("};\n")
	f.close()

	if args.verbose:
		print "Writing " + out_dir + "/" + font_name + ".h"
	f = open(out_dir + "/" + font_name + ".h", 'wb+')
	write_comment(f)
	f.write("#ifndef __" + font_name.upper() + "_H\n");
	f.write("#define __" + font_name.upper() + "_H\n");
	f.write("#include \"font.h\"\n")
	f.write("extern const struct font font_" + font_name + ";\n")
	f.write("#endif /*__" + font_name.upper() + "_H*/\n");
	f.close()
开发者ID:CadeLaRen,项目名称:optee_os,代码行数:78,代码来源:render_font.py

示例10: Image

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
        pages = 1
        
        image = Image(
            width = imageFromPdf.width,
            height = imageFromPdf.height*pages          
           
        )
        
        for i in range(pages):
            image.composite(
                imageFromPdf.sequence[i],
                top = imageFromPdf.height * i,
                left = 0
            )
            
        image.resize(250,250)
        image.alpha_channel = False
        image.format = 'png'
        print(image.size)
        image.background_color = Color('pink')
        
        image.type = 'grayscale'
        image.caption = file.split('.')[0]
        image.save(filename = fileDirectory+file.split('.')[0]+".png")

        image.clear()
        image.close()

        #display(image)
开发者ID:alamsal,项目名称:thumbnailsFromPdf,代码行数:31,代码来源:extract_images.py

示例11: compose_main_slide

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import close [as 别名]
    def compose_main_slide(self, primary_text=None, secondary_text=None, overlay_image_path=None, slide_id=0):

        if overlay_image_path and os.path.isfile(overlay_image_path):
            key = '%s-%s-%03d' % (self.emission.uuid, self.content_object.uuid, slide_id)
            path = os.path.join(SLIDE_BASE_DIR, key + '.{}'.format(IMAGE_OUTPUT_FORMAT))
            url = SLIDE_BASE_URL + key + '.{}'.format(IMAGE_OUTPUT_FORMAT)
        else:
            # TODO: not used anymore
            overlay_image_path = SLIDE_DEFAULT_IMAGE
            key = 'default'
            path = os.path.join(SLIDE_BASE_DIR, key + '.png')
            url = SLIDE_BASE_URL + key + '.png'


        overlay_image = Image(filename=overlay_image_path)

        with Drawing() as draw:

            # add overlay image
            draw.composite('over', left=210, top=10, width=100, height=100, image=overlay_image)

            # text settings
            # draw.font = SLIDE_BASE_FONT
            # draw.font_size = 14
            # draw.text_interline_spacing = 8
            # draw.fill_color = Color('white')
            # draw.text_antialias = True

            # text settings
            draw.font = SLIDE_BASE_FONT
            draw.font_size = 14
            draw.text_interline_spacing = 8
            draw.fill_color = Color('white')
            draw.text_antialias = True

            # draw text
            if primary_text:
                draw.text(10, 28, primary_text)

            if secondary_text:
                draw.font_size = 13
                draw.text_interline_spacing = 5
                draw.text(10, 140, secondary_text)

            # compose image
            with Image(filename=SLIDE_BASE_IMAGE) as image:
                draw(image)

                if IMAGE_OUTPUT_FORMAT == 'jpg':
                    image.compression_quality = 70
                    image.format = 'jpeg'

                image.save(filename=path)
                image.save(filename=os.path.join(SLIDE_BASE_DIR, 'debug-{}.{}'.format(slide_id, IMAGE_OUTPUT_FORMAT)))

        try:
            overlay_image.close()
        except Exception as e:
            # TODO: use narrowed exception(s)
            log.warning('unable to close magick/wand overlay image - {}'.format(e))


        return url
开发者ID:hzlf,项目名称:openbroadcast.org,代码行数:65,代码来源:generator.py


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