本文整理匯總了Python中pgmagick.api.Image.write方法的典型用法代碼示例。如果您正苦於以下問題:Python Image.write方法的具體用法?Python Image.write怎麽用?Python Image.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pgmagick.api.Image
的用法示例。
在下文中一共展示了Image.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_fontpointsize
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def test_fontpointsize(self):
img = Image((300, 200), 'red')
img.font_pointsize(60)
self.assertEqual(60, img.font_pointsize())
self.assertEqual(float, type(img.font_pointsize()))
img.annotate("hello", (100, 100))
img.write('t.png')
示例2: test_composite_arg_gravity
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def test_composite_arg_gravity(self):
base = Image((300, 200), 'green')
layer = Image((150, 100), 'transparent')
drawer = Draw()
drawer.circle(50, 50, 20, 20)
layer.draw(drawer)
base.composite(layer, 'center', 'over')
base.write('t.png')
示例3: test_fontpointsize
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def test_fontpointsize(self):
img = Image((300, 200), 'red')
img.font_pointsize(60)
self.assertEqual(60, img.font_pointsize())
self.assertEqual(float, type(img.font_pointsize()))
if sys.platform.lower() == 'darwin':
img.font("/Library/Fonts/Arial.ttf")
img.annotate("hello", (100, 100))
img.write('t.png')
示例4: test_unicodefilename
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def test_unicodefilename(self):
self.img.write('unicode.png')
if sys.version_info >= (3, ):
img = Image('unicode.png')
else:
img = Image(unicode('unicode.png'))
img.scale(0.5)
if sys.version_info >= (3, ):
img.write('unicode.jpg')
else:
img.write(unicode('unicode.jpg'))
示例5: _ensure
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def _ensure(id_, folderer, getter):
folder = folderer(id_)
# Create folder if it does not exists
if not os.path.exists(folder):
os.makedirs(folder)
# Download image
original = os.path.join(folder, ORIGINAL_FILENAME)
if not os.path.exists(original):
getter(original)
# Create thumbnail
thumb = os.path.join(folder, THUMBNAIL_FILENAME)
if os.path.exists(original) and not os.path.exists(thumb):
img = Image(original)
img.scale((THUMBNAIL_SIZE, THUMBNAIL_SIZE))
img.write(thumb)
示例6: write
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def write(self, filename):
try:
return Image.write(self, filename)
except Exception as e:
if 'Warning' not in e.message:
raise
warnings.warn(e.message, RuntimeWarning)
示例7: pdf_to_images
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def pdf_to_images(self, ext="jpg"):
''' PDF to images '''
assert os.path.isfile(self.data.path)
i = 0
medias = []
while Image and True:
try:
image = Image("%s[%d]" % (self.data.path, i))
image_file = os.path.join(
UPLOAD_TMP_DIR,
'pdf.%d.%d.%s' % (self.id, i, ext))
image.write(image_file)
media = MediaFile.create(
image_file, name=image_file.split('/')[-1:][0])
medias.append(media)
except Exception:
#:TODO Exception type check
break
i = i + 1
return medias
示例8: test_scale_with_filtertype
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def test_scale_with_filtertype(self):
img = Image((600, 400), 'gradient:#ffffff-#000000')
img.scale(0.6, 'Catrom')
img.write('t.jpg')
m = hashlib.md5()
with open('t.jpg', 'rb') as fp:
m.update(fp.read())
scale_with_filtertype_catrom_digest = m.hexdigest()
img = Image((600, 400), 'gradient:#ffffff-#000000')
img.scale(0.6, 'Cubic')
img.write('t.jpg')
m = hashlib.md5()
with open('t.jpg', 'rb') as fp:
m.update(fp.read())
scale_with_filtertype_cubic_digest = m.hexdigest()
img = Image((600, 400), 'gradient:#ffffff-#000000')
img.scale(0.6)
img.write('t.jpg')
m = hashlib.md5()
with open('t.jpg', 'rb') as fp:
m.update(fp.read())
scale_digest = m.hexdigest()
self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_digest)
self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_with_filtertype_cubic_digest)
示例9: DrawTestCase
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
class DrawTestCase(unittest.TestCase):
def setUp(self):
self.im = Image((600, 400), 'red')
self.d = Draw()
def test_affine(self):
self.d.affine(10, 10, 20, 20, 40, 40)
self.im.draw(self.d.drawer)
self.im.write('t.jpg')
def test_arc(self):
self.d.arc(30, 30, 40, 40, 40, 40)
self.im.draw(self.d.drawer)
self.im.write('t.jpg')
def test_bezier(self):
points = ((30, 30), (50, 75), (200, 100))
self.d.bezier(points)
self.im.draw(self.d.drawer)
self.im.write('t.png')
def test_circle(self):
self.d.circle(40, 40, 50, 100)
self.im.draw(self.d.drawer)
self.im.write('t.png')
def test_color(self):
self.d.color(40, 40, 'point')
self.im.draw(self.d.drawer)
self.im.write('t.png')
def test_composite(self):
img1 = Image((20, 20), 'plasma:blue')
self.d.composite(10, 10, 0, 0, img1)
self.im.draw(self.d)
self.im.write('t.png')
def test_draw_for_draw_class(self):
self.d.color(40, 40, 'point')
self.d.circle(100, 100, 50, 100)
self.im.draw(self.d)
self.im.write('t.png')
def test_ellipse(self):
self.d.ellipse(150, 150, 120, 120, 0, 120)
self.im.draw(self.d)
self.im.write('t.png')
def test_fill_color(self):
self.d.fill_color('#f09060')
self.d.ellipse(150, 150, 120, 120, 0, 120)
self.im.draw(self.d)
self.im.write('t.png')
def test_fill_rule(self):
self.d.fill_rule('evenodd')
self.d.circle(150, 150, 50, 180)
self.d.fill_rule('nonzero')
self.d.circle(350, 150, 250, 180)
self.im.draw(self.d.drawer)
self.im.write('t.png')
def test_fill_opacity(self):
self.im = Image((600, 400), 'transparent')
self.d.fill_color('red')
self.d.fill_opacity(0.5)
self.d.circle(150, 150, 50, 180)
self.d.fill_color('green')
self.d.fill_opacity(0.8)
self.d.circle(160, 160, 50, 180)
self.im.draw(self.d.drawer)
self.im.write('t.png')
def test_font_style_italic(self):
self.d.font('vera.ttf', 'italic')
self.d.text(30, 30, "hello pgmagick")
self.im.draw(self.d)
self.im.write('t.png')
def test_font_style_oblique(self):
self.d.font('vera.ttf', 'oblique')
self.d.text(30, 30, "hello pgmagick")
self.im.draw(self.d)
self.im.write('t.png')
def test_font_stretch_ultracondensed(self):
self.d.font('vera.ttf', 'oblique', stretch='ultracondensed')
self.d.text(30, 30, "hello pgmagick")
self.im.draw(self.d)
self.im.write('t.png')
def test_font_stretch_extraexpanded(self):
self.d.font('vera.ttf', 'oblique', stretch='extraexpanded')
self.d.text(30, 30, "hello pgmagick")
self.im.draw(self.d)
self.im.write('t.png')
def test_font_weight100(self):
self.d.font('vera.ttf', weight=100)
#.........這裏部分代碼省略.........
示例10: ImageTestCase
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
class ImageTestCase(unittest.TestCase):
def setUp(self):
self.img = Image((600, 400), 'red')
def test_unicodefilename(self):
self.img.write('unicode.png')
if sys.version_info >= (3, ):
img = Image('unicode.png')
else:
img = Image(unicode('unicode.png'))
img.scale(0.5)
if sys.version_info >= (3, ):
img.write('unicode.jpg')
else:
img.write(unicode('unicode.jpg'))
def test_nonarg(self):
im = Image()
def test_arg(self):
im = Image((600, 400), 'red')
def test_arg_float(self):
im = Image((600.5, 400.4), 'red')
def test_blur(self):
self.img.blur(2, 2.3)
self.img.write('t.jpg')
def test_blur_channel(self):
self.img.blur_channel('cyan')
self.img.write('t.jpg')
def test_scale(self):
im = Image((600, 400), 'red')
im.scale(0.6)
im.write('t.jpg')
def test_composite_arg_list(self):
base = Image((300, 200), 'green')
layer = Image((300, 200), 'transparent')
drawer = Draw()
drawer.circle(50, 50, 50, 100)
layer.draw(drawer)
base.composite(layer, (10, 10), 'over')
base.write('t.png')
def test_composite_arg_gravity(self):
base = Image((300, 200), 'green')
layer = Image((150, 100), 'transparent')
drawer = Draw()
drawer.circle(50, 50, 20, 20)
layer.draw(drawer)
base.composite(layer, 'center', 'over')
base.write('t.png')
def test_crop(self):
img = Image((300, 200), 'gradient:#ffff00-#00ffff')
img.crop(20, 20, 50, 100)
img.write('t.png')
def test_fontpointsize(self):
img = Image((300, 200), 'red')
img.font_pointsize(60)
self.assertEqual(60, img.font_pointsize())
self.assertEqual(float, type(img.font_pointsize()))
img.annotate("hello", (100, 100))
img.write('t.png')
def test_size_property(self):
im = Image((500, 300), 'red')
self.assertEqual(im.width, 500)
self.assertEqual(im.height, 300)
im.scale(0.5)
self.assertEqual(im.width, 250)
self.assertEqual(im.height, 150)
示例11: test_crop
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def test_crop(self):
img = Image((300, 200), 'gradient:#ffff00-#00ffff')
img.crop(20, 20, 50, 100)
img.write('t.png')
示例12: test_scale
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def test_scale(self):
im = Image((600, 400), 'red')
im.scale(0.6)
im.write('t.jpg')
示例13: Image
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
# coding: utf-8
from pgmagick.api import Image
img = Image((300, 200))
img.font("/etc/alternatives/fonts-japanese-gothic.ttf")
img.annotate('Hello World')
img.annotate('ようこそpgmagickへ!!')
img.write('japanese-text.png')
示例14: test_scale
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def test_scale(self):
img = Image((600, 400), 'gradient:#ffffff-#000000')
img.scale(0.6)
img.write('t.jpg')
示例15: test_unicodefilename
# 需要導入模塊: from pgmagick.api import Image [as 別名]
# 或者: from pgmagick.api.Image import write [as 別名]
def test_unicodefilename(self):
self.img.write('unicode.png')
img = Image(u'unicode.png')
img.scale(0.5)
img.write(u'unicode.jpg')