本文整理汇总了Python中pgmagick.Image.size方法的典型用法代码示例。如果您正苦于以下问题:Python Image.size方法的具体用法?Python Image.size怎么用?Python Image.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmagick.Image
的用法示例。
在下文中一共展示了Image.size方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_image
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def get_image( self ):
# Open the image
try:
img_file = urllib.urlopen( self.path )
img_data = img_file.read()
bytes_read = len(img_data)
except urllib.HTTPError as e:
raise ImageRetrievalError(self.path, "Error code: %s" % e.code)
except urllib.URLError as e:
raise ImageRetrievalError(self.path, e.reason)
blob = Blob( img_data )
image = Image( blob )
# Check if the whole image should be used and cropped if necessary.
src_width = image.size().width()
src_height = image.size().height()
if self.width != src_width or self.height != src_height:
box = Geometry( self.width, self.height, self.x_min_src, self.y_min_src )
image.crop( box )
# Estimates the size in Bytes of this image part by scaling the number
# of Bytes read with the ratio between the needed part of the image and
# its actual size.
self.estimated_size = bytes_read * abs(float(self.width * self.height) /
float(src_width * src_height))
return image
示例2: get_image
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def get_image( self ):
# Open the image
img_file = urllib.urlopen( self.path )
blob = Blob( img_file.read() )
image = Image( blob )
# Check if the whole image should be used and croped
# if necessary.
src_width = image.size().width()
src_height = image.size().height()
if self.width != src_width or self.height != src_height:
box = Geometry( self.width, self.height, self.x_min_src, self.y_min_src )
image.crop( box )
return image
示例3: get_image
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def get_image( self ):
# Open the image
try:
img_file = urllib.urlopen( self.path )
except urllib.HTTPError as e:
raise ImageRetrievalError(self.path, "Error code: %s" % e.code)
except urllib.URLError as e:
raise ImageRetrievalError(self.path, e.reason)
blob = Blob( img_file.read() )
image = Image( blob )
# Check if the whole image should be used and cropped if necessary.
src_width = image.size().width()
src_height = image.size().height()
if self.width != src_width or self.height != src_height:
box = Geometry( self.width, self.height, self.x_min_src, self.y_min_src )
image.crop( box )
return image
示例4: generate
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def generate(self, source_path, small_thumb_path, large_thumb_path):
img = Image(source_path)
width = img.size().width()
height = img.size().height()
# Detect if we need to rotate the image by reading EXIF data
orientation = 0
if img.attribute("EXIF:Orientation") != "unknown":
try:
orientation = int(img.attribute("EXIF:Orientation"))
except ValueError:
print ("Invalid EXIF orientation, using default")
# Detect if we need to resize the large thumbnail
if width > LARGE_MAX_WIDTH:
height = int((float(height) / width) * LARGE_MAX_WIDTH)
width = LARGE_MAX_WIDTH
elif height > LARGE_MAX_HEIGHT:
width = int((float(width) / height) * LARGE_MAX_HEIGHT)
height = LARGE_MAX_HEIGHT
# Rescale the large thumbnail if dimensions doesn't match
if width != img.size().width() or height != img.size().height():
img.sample("!%sx%s" % (width, height))
# Rotate the image if needed
if orientation == 6:
img.rotate(90)
elif orientation == 8:
img.rotate(-90)
self.write_image(img, large_thumb_path)
# Crop the small thumbnail and then resize it to the correct size
img.crop("%sx%s" % (min(width, height), min(width, height)))
img.sample("%sx%s" % (SMALL_WIDTH_AND_HEIGHT, SMALL_WIDTH_AND_HEIGHT))
self.write_image(img, small_thumb_path)
示例5: load_image
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def load_image(file, path):
print "Loading image %s..." % file,
try:
file = open(path, 'rb')
except IOError:
print 'exists not'
raise ValueError('Texture exists not')
type, width, height = image_info(file.read(65536))
file.seek(0, 0)
if type:
check_size(width, height)
if magick:
file.close()
file = Image(path.encode('mbcs' if os.name == 'nt' else 'utf8'))
geo = file.size()
check_size(geo.width(), geo.height())
print
blob = Blob()
file.flip()
file.write(blob, 'RGBA')
texture = blob.data
mode = GL_RGBA
else:
try:
raw = image.load(path, file=file)
except IOError:
print 'exists not'
raise ValueError('Texture exists not')
width, height = raw.width, raw.height
check_size(width, height)
print
mode = GL_RGBA if 'A' in raw.format else GL_RGB
# Flip from BGR to RGB
if raw.format in ('BGR', 'BGRA'):
if bgra:
mode = {GL_RGBA: GL_BGRA, GL_RGB: GL_BGR}[mode]
texture = raw.data
else:
texture = bgr_to_rgb(raw.data, width, height, 'A' in raw.format)
elif raw.format in ('RGB', 'RGBA'):
texture = raw.data
else:
texture = raw.get_data('RGBA', width * 4)
return path, width, height, len(raw.format), mode, texture
示例6: bobross
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def bobross(self,imgStr):
print "bobross()"
bob=Image('bob-transparent-canvas.png')
bob.matte(True)
#print "1"
img=Image(imgStr)
#print "2"
newsize=Geometry(200,343)
newsize.aspect(True)
img.scale(newsize)
#print "3"
img=self.watercolor(img)
#print "4"
result=Image(bob.size(),'white')
result.composite(img,392,22,CompositeOperator.OverCompositeOp)
result.composite(bob,0,0,CompositeOperator.OverCompositeOp)
return result
示例7: merge_overlay
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def merge_overlay(self, overlay):
self.open()
overlay.open()
background_image = Image(self.image)
# remove any transparent areas around the logo
overlay_image = Image(Geometry(overlay.image.size().width() + 2, overlay.image.size().height() + 2), 'transparent')
overlay_image.composite(overlay.image, GravityType.CenterGravity, CompositeOperator.OverCompositeOp)
overlay_image.trim()
border_width = int(math.ceil(background_image.size().width() * PIconBackground.BORDER_RATIO))
overlay_image.zoom(Geometry(background_image.size().width() - (border_width * 2), background_image.size().height() - (border_width * 2)))
# we need to calculate exact position since we get 1-pixel error
# if the height of the logo is odd and using GravityType.CenterGravity
if overlay_image.size().width() + (2 * border_width) == background_image.size().width():
x = border_width
y = int(math.ceil((background_image.size().height() / 2.0) - (overlay_image.size().height() / 2.0)))
else:
x = int(math.ceil((background_image.size().width() / 2.0) - (overlay_image.size().width() / 2.0)))
y = border_width
background_image.composite(overlay_image, x, y, CompositeOperator.OverCompositeOp)
return PIcon(background_image)
示例8: watercolor
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def watercolor(self,imgStr):
img=Image(imgStr)
img.blur(2,2)
img.oilPaint(5)
img.enhance()
img.sharpen()
pink=Color(250,218,221,75)
toplayer=Image(img.size(),pink)
toplayer.matte(True)
img.matte(True)
img.composite(toplayer,0,0,CompositeOperator.CopyOpacityCompositeOp)
img.blur(2,2)
#img.write('watercolor-output.png')
return img
示例9: bobross
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def bobross(self,imgStr):
bob=Image('bob-transparent-canvas.png')
bob.matte(True)
img=self.watercolor(imgStr)
#img.matte(True)
newsize=Geometry(210,380)
newsize.aspect(True)
img.scale(newsize)
#img.oilPaint(3)
#img.enhance()
#img.sharpen()
#img.blur(2,2)
#img.shear(-25,-15)
result=Image(bob.size(),'white')
result.composite(img,390,20,CompositeOperator.OverCompositeOp)
result.composite(bob,0,0,CompositeOperator.OverCompositeOp)
#img.debug(True)
#bob.composite(img,390,20,CompositeOperator.OverCompositeOp)
return result
示例10: load_texture
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def load_texture(file):
if file in cache:
return cache[file]
print "Loading image %s..." % file,
path = os.path.join(os.path.dirname(__file__), "assets", "textures", file)
try:
file = open(path, 'rb')
except IOError:
print 'exists not'
raise ValueError('Texture exists not')
type, width, height = image_info(file.read(8192))
file.seek(0, 0)
if type:
check_size(width, height)
if magick:
file.close()
file = Image(path.encode('mbcs' if os.name == 'nt' else 'utf8'))
geo = file.size()
check_size(geo.width(), geo.height())
print
blob = Blob()
file.flip()
file.write(blob, 'RGBA')
texture = blob.data
mode = GL_RGBA
else:
try:
raw = image.load(path, file=file)
except IOError:
print 'exists not'
raise ValueError('Texture exists not')
width, height = raw.width, raw.height
check_size(width, height)
print
mode = GL_RGBA if 'A' in raw.format else GL_RGB
# Flip from BGR to RGB
# I hate you too, Pyglet...
# REGULAR EXPRESSIONS ARE NOT MEANT TO PARSE BINARY DATA!!!
#texture = raw.get_data('RGBA', width * 4) if safe else raw.data[::-1] if 'BGR' in raw.format else raw.data
if raw.format in ('BGR', 'BGRA'):
texture = bgr_to_rgb(raw.data, width, height, 'A' in raw.format)
elif raw.format in ('RGB', 'RGBA'):
texture = raw.data
else:
texture = raw.get_data('RGBA', width * 4)
buffer = c_ulong()
glGenTextures(1, byref(buffer))
id = buffer.value
glBindTexture(GL_TEXTURE_2D, id)
filter = GL_NEAREST if badcard else GL_LINEAR
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter)
glTexImage2D(GL_TEXTURE_2D, 0, mode, width, height, 0, mode, GL_UNSIGNED_BYTE, texture)
cache[file] = id
return id
示例11: test_size_and_color_init
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def test_size_and_color_init(self):
im = Image(Geometry(300, 200), Color('transparent'))
size = im.size()
self.assertEqual(300, size.width())
self.assertEqual(200, size.height())
示例12: len
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
# Make sure we got the arguments we expect
if len(sys.argv) != 3:
print >> sys.stderr, "Usage: ensure_tilesize.py <FILENAME> <TILESIZE>"
sys.exit(1)
image_path = sys.argv[1]
tile_size = int(sys.argv[2])
# Make sure the file actually exists
if not os.path.exists(image_path):
print >> sys.stderr, "Could not find file!"
sys.exit(1)
# Get properties of image
image = Image(image_path)
image_width = image.size().width()
image_height = image.size().height()
image_name = image.fileName()
# If the image has the correct size, just exit
if image_width == tile_size and image_height == tile_size:
sys.exit(0)
# A new image with the correct size is needed, create it
geometry = Geometry(tile_size, tile_size)
color = Color("black")
new_image = Image(geometry, color)
# Copy original image to position 0,0 of new image
new_image.composite(image, 0, 0, co.OverCompositeOp)
# Override original image
new_image.write(image_name)
示例13: Blob
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
from pgmagick import Image, Blob
blob = Blob(open('X.jpg').read())
img = Image(blob)
size = img.size()
pixels = img.getPixels(0, 0, size.width()/2, size.height()/2)
for cnt, pixel in enumerate(pixels):
if False:
print(pixel.red, pixel.blue, pixel.green, pixel.opacity)
pixel.blue = pixel.blue / 2
pixel.green = pixel.green / 2
pixel.red = pixel.red / 2
img.syncPixels()
img.write("Xo.jpg")
示例14: test_image_init_RGBA_XWD_header
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import size [as 别名]
def test_image_init_RGBA_XWD_header(self):
data = b"\0\0\0\0\4\0\0\0" + 92 * b"\0"
img = Image(5, 5, "RGBA", StorageType.CharPixel, data)
self.assertEqual(5, img.size().height())
self.assertEqual(5, img.size().width())