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


Python images.Image方法代码示例

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


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

示例1: get

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def get(self):
        blob_key = self.request.get("blob_key")
        if blob_key:
            blob_info = blobstore.get(blob_key)

            if blob_info:
                img = images.Image(blob_key=blob_key)
                img.resize(width=80, height=100)
                img.im_feeling_lucky()
                thumbnail = img.execute_transforms(output_encoding=images.JPEG)

                self.response.headers['Content-Type'] = 'image/jpeg'
                self.response.out.write(thumbnail)
                return

        # Either "blob_key" wasn't provided, or there was no value with that ID
        # in the Blobstore.
        self.error(404)
# [END thumbnailer] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:21,代码来源:blobstore.py

示例2: get

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def get(self):
        if self.request.get("id"):
            photo = Photo.get_by_id(int(self.request.get("id")))

            if photo:
                img = images.Image(photo.full_size_image)
                img.resize(width=80, height=100)
                img.im_feeling_lucky()
                thumbnail = img.execute_transforms(output_encoding=images.JPEG)

                self.response.headers['Content-Type'] = 'image/jpeg'
                self.response.out.write(thumbnail)
                return

        # Either "id" wasn't provided, or there was no image with that ID
        # in the datastore.
        self.error(404)
# [END thumbnailer] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:20,代码来源:main.py

示例3: validate_django_image

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def validate_django_image(uploaded_file):
    """Tries to convert an image from Django to an Images API object.

    This is essentially a variant of validate_image, above, but for images that
    are uploaded to a Django handler (which gives us something different than
    webapp2 did). If the image is validated, it returns an Image object (from
    the App Engine Images API). Otherwise, it returns False.
    """
    try:
        image = None
        if uploaded_file:
            image = images.Image(uploaded_file.read())
            image.width
        return image
    except:
        return False 
开发者ID:google,项目名称:personfinder,代码行数:18,代码来源:utils.py

示例4: test_upload_photos_with_transformation

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def test_upload_photos_with_transformation(self):
        """Uploads both profile photo and note photo and verifies the images are
        properly transformed and served on the server i.e., jpg is converted to
        png and a large image is resized to match MAX_IMAGE_DIMENSION."""
        # Create a new person record with a profile photo and a note photo.
        with open('tests/testdata/small_image.png') as photo:
            with open('tests/testdata/large_image.png') as note_photo:
                original_image = images.Image(photo.read())
                doc = self.submit_create(photo=photo, note_photo=note_photo)
        # Verify the images are uploaded and displayed on the view page.
        photos = doc.cssselect('img.photo')
        assert len(photos) == 2
        # Verify the profile image is converted to png.
        doc = self.s.go(photos[0].get('src'))
        image = images.Image(doc.content_bytes)
        assert image.format == images.PNG
        assert image.width == original_image.width
        assert image.height == original_image.height
        # Verify the note image is resized to match MAX_IMAGE_DIMENSION.
        doc = self.s.go(photos[1].get('src'))
        image = images.Image(doc.content_bytes)
        assert image.format == images.PNG
        assert image.width == MAX_IMAGE_DIMENSION
        assert image.height == MAX_IMAGE_DIMENSION 
开发者ID:google,项目名称:personfinder,代码行数:26,代码来源:photo_tests.py

示例5: test_skip_thumbnail_for_small_enough_images

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def test_skip_thumbnail_for_small_enough_images(self):
        """Tests that a thumbnail isn't generated for small enough images."""
        with open('tests/testdata/tiny_image.png') as image_file:
            photo = model.Photo.create('haiti', image_data=image_file.read())
        photo.save()
        self.go('/haiti/tasks/thumbnail_preparer')
        db_photo = model.Photo.get_by_key_name(photo.key().name())
        # tiny_image.png is 40x40, so it shouldn't bother generating a
        # thumbnail.
        assert not db_photo.thumbnail_data
        doc = self.s.go('/haiti/photo?id=%s&thumb=true' %
                        photo.key().name().split(':')[1])
        image = images.Image(doc.content_bytes)
        assert image.format == images.PNG
        assert image.height == 40
        assert image.width == 40 
开发者ID:google,项目名称:personfinder,代码行数:18,代码来源:photo_tests.py

示例6: import_image

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def import_image(self, filename, original_filename, bytes, date, email_attachment_content_id):

		content_type = self.get_content_type(original_filename)
		self.original_size_key = filename
		filestore.write(self.original_size_key, bytes, content_type)

		MAX_SIZE = 500
		image = images.Image(bytes)

		if image.width <= MAX_SIZE and image.width <= MAX_SIZE:
			logging.info('%s is only %sx%s, no resizing will be done' % (original_filename, image.width, image.height))
			resized_bytes = bytes
		else:
			if image.width > image.height:
				new_width = MAX_SIZE
				new_height = int(float(MAX_SIZE) / image.width * image.height)
			else:
				new_height = MAX_SIZE
				new_width = int(float(MAX_SIZE) / image.height * image.width)

			logging.info('Resizing %s from %sx%s to %sx%s' % (original_filename, image.width, image.height, new_width, new_height))
			resized_bytes = images.resize(bytes, MAX_SIZE, MAX_SIZE)


		self.serving_size_key = self.get_small_image_name(filename)
		filestore.write(self.serving_size_key, resized_bytes, content_type)
		self.original_filename = original_filename
		self.filename = filename

		self.email_attachment_content_id = email_attachment_content_id
		self.date = date 
开发者ID:einaregilsson,项目名称:MyLife,代码行数:33,代码来源:userimage.py

示例7: write_blob

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def write_blob(self, data, info):
        key = urllib.quote(info['type'].encode('utf-8'), '') +\
            '/' + str(hash(data)) +\
            '/' + urllib.quote(info['name'].encode('utf-8'), '')
        try:
            memcache.set(key, data, time=EXPIRATION_TIME)
        except: #Failed to add to memcache
            return (None, None)
        thumbnail_key = None
        if IMAGE_TYPES.match(info['type']):
            try:
                img = images.Image(image_data=data)
                img.resize(
                    width=THUMB_MAX_WIDTH,
                    height=THUMB_MAX_HEIGHT
                )
                thumbnail_data = img.execute_transforms()
                thumbnail_key = key + THUMB_SUFFIX
                memcache.set(
                    thumbnail_key,
                    thumbnail_data,
                    time=EXPIRATION_TIME
                )
            except: #Failed to resize Image or add to memcache
                thumbnail_key = None
        return (key, thumbnail_key) 
开发者ID:chaijunit,项目名称:beibq,代码行数:28,代码来源:main.py

示例8: validate_image

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def validate_image(bytestring):
    try:
        image = None
        if bytestring:
            image = images.Image(bytestring)
            image.width
        return image
    except:
        return False 
开发者ID:google,项目名称:personfinder,代码行数:11,代码来源:utils.py

示例9: create_photo

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def create_photo(image, repo, url_builder):
    """Creates a new Photo entity for the provided image of type images.Image
    after resizing it and converting to PNG.  It may throw a PhotoError on
    failure, which comes with a localized error message appropriate for
    display."""
    if image == False:  # False means it wasn't valid (see validate_image)
        raise FormatUnrecognizedError()

    if max(image.width, image.height) <= MAX_IMAGE_DIMENSION:
        # No resize needed.  Keep the same size but add a transformation to
        # force re-encoding.
        image.resize(image.width, image.height)
    elif image.width > image.height:
        image.resize(MAX_IMAGE_DIMENSION,
                     image.height * MAX_IMAGE_DIMENSION / image.width)
    else:
        image.resize(image.width * MAX_IMAGE_DIMENSION / image.height,
                     MAX_IMAGE_DIMENSION)

    try:
        image_data = image.execute_transforms(output_encoding=images.PNG)
    except RequestTooLargeError:
        raise SizeTooLargeError()
    except Exception:
        # There are various images.Error exceptions that can be raised, as well
        # as e.g. IOError if the image is corrupt.
        raise PhotoError()

    photo = model.Photo.create(repo, image_data=image_data)
    photo_url = get_photo_url(photo, repo, url_builder)
    return (photo, photo_url) 
开发者ID:google,项目名称:personfinder,代码行数:33,代码来源:photo.py

示例10: set_thumbnail

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def set_thumbnail(photo):
    """Sets thumbnail data for a photo.

    Args:
        photo: the Photo object to set the thumbnail for
    """
    image = images.Image(photo.image_data)
    if max(image.width, image.height) <= MAX_THUMBNAIL_DIMENSION:
        # Don't need a thumbnail, it's small enough already.
        return
    elif image.width > image.height:
        image.resize(MAX_THUMBNAIL_DIMENSION,
                     image.height * MAX_THUMBNAIL_DIMENSION / image.width)
    else:
        image.resize(image.width * MAX_THUMBNAIL_DIMENSION / image.height,
                     MAX_THUMBNAIL_DIMENSION)
    try:
        thumbnail_data = image.execute_transforms(output_encoding=images.PNG)
    except RequestTooLargeError:
        raise SizeTooLargeError()
    except Exception:
        # There are various images.Error exceptions that can be raised, as well
        # as e.g. IOError if the image is corrupt.
        raise PhotoError()

    photo.thumbnail_data = thumbnail_data
    photo.save() 
开发者ID:google,项目名称:personfinder,代码行数:29,代码来源:photo.py

示例11: post

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def post(self):
        if not (self.auth and self.auth.domain_write_permission):
            self.info(
                403,
                message='Missing or invalid authorization key',
                style='plain')
            return

        # Check for empty body
        if not self.request.body:
            self.error(400, "Request body must not be empty")
            return

        # Size check for uploaded file
        if len(self.request.body) > PHOTO_UPLOAD_MAX_SIZE:
            self.error(400, "Size of uploaded file is greater than 10MB")
            return

        try:
            photo_img = images.Image(self.request.body)
            photo, photo_url = create_photo(
                photo_img, self.repo, self.transitionary_get_url)
        except PhotoError, e:
            self.error(400, e.message)

        # If we reached this point, it means photo is filled properly
        # So feel free to use it right away! 
开发者ID:google,项目名称:personfinder,代码行数:29,代码来源:api.py

示例12: test_set_thumbnail

# 需要导入模块: from google.appengine.api import images [as 别名]
# 或者: from google.appengine.api.images import Image [as 别名]
def test_set_thumbnail(self):
        """Tests that a thumbnail is generated."""
        with open('tests/testdata/small_image.png') as image_file:
            photo = model.Photo.create('haiti', image_data=image_file.read())
        photo.save()
        self.go('/haiti/tasks/thumbnail_preparer')
        doc = self.s.go('/haiti/photo?id=%s&thumb=true' %
                        photo.key().name().split(':')[1])
        image = images.Image(doc.content_bytes)
        assert image.format == images.PNG
        assert image.height == MAX_THUMBNAIL_DIMENSION
        assert image.width == MAX_THUMBNAIL_DIMENSION 
开发者ID:google,项目名称:personfinder,代码行数:14,代码来源:photo_tests.py


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