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


Python Image.resize方法代码示例

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


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

示例1: _pdf_thumbnail

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
def _pdf_thumbnail(filename):
    img = WandImage(filename=filename + '[0]')
    img.background_color = Color('white')
    tw, th = get_thumbnail_size(img.height, img.width, 50, 50)
    img.resize(tw, th)
    rawData = img.make_blob('jpeg')
    return base64.b64encode(rawData)
开发者ID:CaliopeProject,项目名称:CaliopeServer,代码行数:9,代码来源:thumbnails.py

示例2: appicon

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
def appicon(source_image, dest_dir, size_dict):

    if not os.path.isdir(dest_dir):
        print('the directory does not exist')
        return

    name = size_dict.get('name')
    size_dict = size_dict.get('sizes')

    dt = datetime.datetime.today()
    dtstring =  dt.strftime("%Y-%m-%d %H-%M-%S")

    dest_dir = os.path.join(dest_dir, '{}_{}'.format(name, dtstring))
    os.makedirs(dest_dir)

    img_name, file_ext = os.path.splitext(source_image)
    if file_ext not in ('.jpg', '.jpeg', '.png'):
        return

    for name, size in size_dict.iteritems():

        img = Image(filename=source_image)
        img.resize(size, size)

        img.format = 'png'
        img.save(filename=os.path.join(dest_dir, '{}.png'.format(name)))
开发者ID:petfactory,项目名称:python,代码行数:28,代码来源:image.py

示例3: do_polaroid

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
def do_polaroid (image, filename=None, background="black", suffix=None):
  if suffix is None:
    suffix = PARAMS["IMG_FORMAT_SUFFIX"]
  tmp = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
  tmp.close()
  
  print("Saving image into {}...".format(tmp.name))
  image.save(filename=tmp.name)
  print("Done")
  
  if not(PARAMS["WANT_NO_CAPTION"]) and filename:
    details = get_file_details(filename)
    caption = """-caption "%s" """ % details.replace("'", "\\'")
  else:
    caption = ""
    
  command = ("convert "
             "-bordercolor snow "+
             "-background %(bg)s "+
             "-gravity center %(caption)s "+
             "+polaroid %(name)s %(name)s") % {"bg" : background, "name":tmp.name, "caption":caption}
             
  ret = subprocess.call(command, shell=True)
  if ret != 0:
    raise Exception("Command failed: "+ command)
  
  img = Image(filename=tmp.name).clone()
  
  os.unlink(tmp.name)
  
  img.resize(width=image.width, height=image.height)

  return img
开发者ID:wazari972,项目名称:photowall,代码行数:35,代码来源:photowall.py

示例4: _create_or_update_pdf_thumbnail

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
def _create_or_update_pdf_thumbnail(context,pkg_dict_or_resource):
  pdf_url=pkg_dict_or_resource['url']
  filename, file_extension = os.path.splitext(pdf_url)

  if ".pdf" != file_extension.lower() or pkg_dict_or_resource['name'] == "PDF Thumbnail":
   return

  enabled_pdf_preview = h.asbool(config.get("ckan.odm_nav_concept.generate_pdf_preview", False))
  if enabled_pdf_preview:

    try:

      pdf=Image(filename=pdf_url+"[0]")
      pdf.format='png'
      pdf.resize(135,201)
      temp_dir = os.path.abspath(tempfile.mkdtemp())
      temp_img=temp_dir+'/'+pkg_dict_or_resource['id']+'.png'
      pdf.save(filename=temp_img)
      params = {'package_id':pkg_dict_or_resource['package_id'],'upload':temp_img, 'url':'N/A','format':'PNG','mimetype_inner':'image/png','name':'PDF Thumbnail'}
      ckan_url = config.get("ckan.site_url", "")
      userobj = context['auth_user_obj']
      ckan_auth = userobj.apikey

      if context['resource'].name == "PDF Thumbnail":
        resource_id=context['resource'].id
        params['id']=resource_id
        requests.post(ckan_url + 'api/3/action/resource_update',verify=False,data=params,headers={"X-CKAN-API-Key": ckan_auth},files=[('upload', file(params["upload"]))])
      else:
        requests.post(ckan_url + 'api/3/action/resource_create',verify=False,data=params,headers={"X-CKAN-API-Key": ckan_auth},files=[('upload', file(params["upload"]))])

      if os.path.exists(temp_img):
        os.remove(temp_img)

    except Exception, e:
      log.error("Could not generate PDF thumbnail", e)
开发者ID:OpenDevelopmentMekong,项目名称:ckanext-odm_laws,代码行数:37,代码来源:plugin.py

示例5: main

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
def main(argv):
  input_file_spec = ''
  output_file_path = ''
  if len(argv) != 3:
    print 'usage: proeprocess_images.py <input_file_spec> <output_path>'
    sys.exit(-1)

  input_file_spec = argv[1]
  output_file_path = argv[2]

  file_number = 1
  file_path = input_file_spec % file_number
  while os.path.exists(file_path):
    output_root_file = os.path.splitext(os.path.basename(file_path))[0]
    output_path = os.path.join(output_file_path, output_root_file + '.tiff')
    print 'processing %s to %s' % (file_path, output_path)
    img = Image(filename=file_path)
    # remove any letterboxing from top and bottom, unfortunately this eats other
    # elements too which can end up interfering negatively with cropping
#    trimmer = img.clone()
#    trimmer.trim()
#    if trimmer.size[0] > 1:
#      img = trimmer
#      img.reset_coords()
    # resize to 180px tall at original aspect ratio
    original_size = img.size
    scale = 192.0 / float(original_size[1])
    scale_width = int(scale * float(original_size[0]))
    # always make even width for centering, etc.
#    if scale_width % 2 == 1:
#      scale_width -= 1
    img.resize(width=scale_width, height=192)
    img.save(filename=output_path)
    file_number += 1
    file_path = input_file_spec % file_number
开发者ID:lnihlen,项目名称:vcsmc,代码行数:37,代码来源:preprocess_images.py

示例6: convert

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
 def convert(self, PDFname):
   p = Image(file = PDFname, format = 'png')
   p = p.sequence[0]
   p = Image(p)
   p.resize(50, 50)
   #p.save(filename = "test.png") #This line is for demos
   return p
开发者ID:jenkinjk,项目名称:RHIT-Senior-Project-Open-Access-Publishing-System-Sean-Feeney,代码行数:9,代码来源:PDF_To_PNG_Converter.py

示例7: wand1

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
def wand1():
    """This is Python Wand example 1"""
    the_time = t.asctime()

    print "Importing image ", IFILE
    img_1 = Image(filename=IFILE)

    print "Cropping and resizing the image"
    img_1.crop(300, 0, width=300, height=282)
    img_1.resize(width=600, height=564)

    print "Creating a drawing and overlaying on it"
    draw = Drawing()

    draw.circle((100, 100), (120, 120))

    draw.rectangle(left=img_1.width-300, top=img_1.height-45, width=230,
               height=40, radius=5)

    draw.font_size = 17
    draw.fill_color = Color('white')
    draw.text_color = Color('white')
    draw.text(img_1.width-290, img_1.height-20, the_time)
    draw(img_1)

    print "Displaying, close the XTERM when done"
    display(img_1)
开发者ID:wadester,项目名称:wh_test_py,代码行数:29,代码来源:gr_wand1.py

示例8: create_thumb

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
    def create_thumb(self, img_path, date, text):

        img = Image(filename=os.path.join(self.source_dir, img_path))
        img.resize(self.thumb_size, self.thumb_size)

        pixmap_on = QtGui.QPixmap()
        pixmap_on.loadFromData(img.make_blob())

        with Drawing() as draw:
            draw.stroke_color = Color('white')
            draw.stroke_width = 3
            draw.line((0, 0), (self.thumb_size, self.thumb_size))
            draw.line((0, self.thumb_size), (self.thumb_size , 0))
            draw(img)

        pixmap_off = QtGui.QPixmap()
        pixmap_off.loadFromData(img.make_blob())
        
        btn = IconButton(pixmap_on, pixmap_off, img_path, date, text)
        btn.clicked.connect(self.thumb_clicked)

        size = pixmap_on.size()
        w, h = size.toTuple()
        btn.setIconSize(size)
        btn.setFixedSize(w+20, h+20)

        self.scroll_vbox.addWidget(btn)
开发者ID:petfactory,项目名称:python,代码行数:29,代码来源:instagram_ui.py

示例9: compose_image_slide

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [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

示例10: convert_image

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
def convert_image(pngfile, pf, outdir=".",
                  resize=1000, format="jpeg", rotate=0,
                  rows=':', cols=':', labelrows=None, labelcols=None):
    resizefile = op.join(outdir, pf + ".resize.jpg")
    mainfile = op.join(outdir, pf + ".main.jpg")
    labelfile = op.join(outdir, pf + ".label.jpg")
    img = Image(filename=pngfile)
    exif = dict((k, v) for k, v in img.metadata.items() if k.startswith('exif:'))

    # Rotation, slicing and cropping of main image
    if rotate:
        img.rotate(rotate)
    if resize:
        w, h = img.size
        if min(w, h) > resize:
            if w < h:
                nw, nh = resize, resize * h / w
            else:
                nw, nh = resize * w / h, resize
            img.resize(nw, nh)
            logging.debug("Image `{0}` resized from {1}px:{2}px to {3}px:{4}px".\
                            format(pngfile, w, h, nw, nh))
    img.format = format
    img.save(filename=resizefile)

    rimg = img.clone()
    if rows != ':' or cols != ':':
        w, h = img.size
        ra, rb = slice(rows, h)
        ca, cb = slice(cols, w)
        # left, top, right, bottom
        logging.debug("Crop image to {0}:{1} {2}:{3}".format(ra, rb, ca, cb))
        img.crop(ca, ra, cb, rb)
        img.format = format
        img.save(filename=mainfile)
    else:
        mainfile = resizefile

    # Extract text labels from image
    if labelrows or labelcols:
        w, h = rimg.size
        if labelrows and not labelcols:
            labelcols = ':'
        if labelcols and not labelrows:
            labelrows = ':'
        ra, rb = slice(labelrows, h)
        ca, cb = slice(labelcols, w)
        logging.debug("Extract label from {0}:{1} {2}:{3}".format(ra, rb, ca, cb))
        rimg.crop(ca, ra, cb, rb)
        rimg.format = format
        rimg.save(filename=labelfile)
    else:
        labelfile = None

    return resizefile, mainfile, labelfile, exif
开发者ID:tanghaibao,项目名称:jcvi,代码行数:57,代码来源:grabseeds.py

示例11: flush

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
 def flush(self, filename, scale=100):
     newImage = Image()
     for i in range(self._current_idx):
         newImage.sequence.append(Image(filename="{0}/capture{1}.miff".format(self._tmp_path,\
                                                                              i)))
     newImage.format = 'gif'
     for i, frame in enumerate(newImage.sequence):
         frame.delay = 50
         frame.destroy()
     (newImageWidth, newImageHeight) = newImage.size
     newImage.resize(width=int(scale * newImageWidth / 100),\
                     height=int(scale * newImageHeight / 100))
     newImage.save(filename=filename)
开发者ID:Paulloz,项目名称:enGIF-your-screen,代码行数:15,代码来源:GifOMatic.py

示例12: resize_if_params

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
    def resize_if_params(self, file_data):
        """ If params width parameter is specified, resize the image
        with wand and return the file data.
        """
        width = self.request.params.get("width")
        if width is None:
            log.info("No width change")
            return file_data

        width = int(width)
        log.debug("Change width to: %s", width)
        new_img = Image(blob=file_data)
        new_img.resize(width, 56)
        return new_img.make_blob()
开发者ID:WasatchPhotonics,项目名称:CookBook,代码行数:16,代码来源:views.py

示例13: write_thumb

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
def write_thumb(params):
	file_name, directory = params
	img = Image(filename=directory + '/' + file_name)
	if not os.path.isdir(directory + '/@eaDir/' + file_name):
		os.mkdir(directory + '/@eaDir/' + file_name)
	img.resize(XLsize, XLsize)
	img.save(filename=directory + '/@eaDir/' + file_name + '/' + XLname)
	img.resize(Lsize, Lsize)
	img.save(filename=directory + '/@eaDir/' + file_name + '/' + Lname)
	img.resize(Bsize, Bsize)
	img.save(filename=directory + '/@eaDir/' + file_name + '/' + Bname)
	img.resize(Msize, Msize)
	img.save(filename=directory + '/@eaDir/' + file_name + '/' + Mname)
	img.resize(Ssize, Ssize)
	img.save(filename=directory + '/@eaDir/' + file_name + '/' + Sname)
开发者ID:amarant,项目名称:diskstationthumbs,代码行数:17,代码来源:MakeThumbs.py

示例14: thumbnail

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
    def thumbnail(self, image_file_path=None, thumbnail_file_path=None):

        if not thumbnail_file_path:
            thumbnail_file_path = self.get_thumbnail_file_path(file_path=image_file_path)

        try:
            img = Image(filename=image_file_path)
            img.resize(self.width, self.height)
            img.save(filename=thumbnail_file_path)

            return thumbnail_file_path

        except Exception as e:
            print "Unable to load image"
            return None
开发者ID:mpoulin,项目名称:pyimgdown,代码行数:17,代码来源:thumbnailer.py

示例15: create_test_data

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import resize [as 别名]
 def create_test_data(self):
     im = Image(filename=root('resources', 'color_circle.png'))
     if self.mode == 'RGB':
         im.type = 'truecolor'
     elif self.mode == 'RGBA':
         im.type = 'truecolormatte'
     elif self.mode == 'L':
         im.type = 'grayscale'
     elif self.mode in 'LA':
         im.type = 'grayscalematte'
     else:
         raise ValueError('Unknown mode: {}'.format(self.mode))
     im.resize(self.size[0], self.size[1], 'catrom')
     self._free_resources.append(im)
     return [im]
开发者ID:homm,项目名称:pillow-perf,代码行数:17,代码来源:wand.py


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