本文整理汇总了Python中pgmagick.Image.write方法的典型用法代码示例。如果您正苦于以下问题:Python Image.write方法的具体用法?Python Image.write怎么用?Python Image.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmagick.Image
的用法示例。
在下文中一共展示了Image.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scale_jpeg
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def test_scale_jpeg(self):
img = api.Image((400, 400), 'blue')
img.write(self.tmp_filename_jpg)
img2 = Image(Blob(open(self.tmp_filename_jpg).read()),
Geometry(200, 200))
img2.scale('200x200')
img2.write(self.tmp_filename_jpg)
示例2: _xor_composite_clip_layer
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def _xor_composite_clip_layer(self, clips, layer_level=0):
"""
round two clipping.
"""
#skip the first clip as it doesn't need anything taken away from it.
this_clip = GMImage(os.path.join(self.clips_dir, 'clip-%s.png' %
clips[0]))
this_clip.write(os.path.join(self.clips_dir, "clip-co-%s.png" %
clips[0]))
#self.masks.append(os.path.join(self.clips_dir, 'clip-co-%s.png' %
#clips[0]))
clip_i = 0
for clip_id in clips[1:]:
previous_clip = GMImage(os.path.join(self.clips_dir, 'clip-%s.png' %
clips[clip_i]))
this_clip = GMImage(os.path.join(self.clips_dir, 'clip-%s.png' %
clip_id))
this_clip.composite(previous_clip, 0, 0, co.XorCompositeOp)
img_file = os.path.join(self.clips_dir, "clip-co-%s.png" % clip_id)
this_clip.write(img_file)
clip_i = clip_i + 1
im = Image.open(img_file)
if not im.getbbox(): # nothing there so delete it
os.unlink(img_file)
示例3: emotion_to_avatar
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def emotion_to_avatar(emotion, font_path, color=Color("black")):
"""使用颜文字(文本)来生成一张方形图片
:type emotion: string
:param emotion: 需要绘制在图像上的文本
:type font_path: string
:param font_path: 字体文件路径
:type color: Color
:param color: 绘制的文本颜色
返回结果是一个 Image 对象,并叫将会被规整到 AVATAR_SIZE 设定的大小
"""
font_size = 128
max_size = len(emotion.decode('utf-8')) * font_size
img = Image(Geometry(max_size, max_size), Color("white"))
img.font(font_path)
img.fontPointsize(font_size)
img.annotate(emotion, GravityType.CenterGravity)
img.trim()
img.write('tmp.png')
height = img.rows()
width = img.columns()
origin_pimg = PImage.open('tmp.png')
new_pimg = PImage.new("RGB", (max(height, width), max(height, width)), "white")
if height > width:
new_pimg.paste(origin_pimg, ((height - width) / 2, 0))
else:
new_pimg.paste(origin_pimg, (0, (width - height) / 2))
return new_pimg.resize(AVATAR_SIZE, PImage.ANTIALIAS)
示例4: test_fromblob
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def test_fromblob(self):
with open('../example/X.jpg', 'rb') as f:
data = f.read()
b = Blob(data)
img = Image(b)
img.write('X2.jpg')
self.assertEqual(type(img), Image)
示例5: thumbnail
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def thumbnail(request, type, identifier):
response = HttpResponse(mimetype="image/png")
size = str(request.GET.get("size", "190x270"))
if not re.match("\d+[x]\d+", size):
size = "190x270"
cache_key = "thumbnail:%s:%s:%s" % (type, identifier, size)
cached = cache.get(cache_key)
if cached is None:
if type == "file":
file_ = str(os.path.join(settings.INCOMING_DIRECTORY, identifier))
elif type == "document":
document = get_object_or_404(Document, pk=identifier)
file_ = Blob(document.document.read())
image = Image(file_)
image.filterType(FilterTypes.SincFilter)
image.scale(size)
output = Blob()
image.write(output, "png")
response.write(output.data)
cache.set(cache_key, output.data)
else:
response.write(cached)
return response
示例6: resize3
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def resize3( srcFile="", destFile="", w=200,h=200, color="", crop=False, align="center" ):
img = Image(srcFile)
img.scale("%dx%d>"%(w,h))
img.profile("*",Blob())
img.write(destFile)
return "True"
示例7: ConvertJp2
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def ConvertJp2(input):
"""
If the input is a jp2 picture, the image is transformed into bmp,
else the image is returned without any modifications.
@param input: A binary string representing the picture to convert
@type input: A string
@return: A binary string representing the picture in bmp, or the original input if the input is not a jp2 stream.
"""
jp2 = open("tmp.jp2", "wb")
jp2.write(input)
jp2.close()
if isMagick == False:
geojasper = "geojasper"
if (sys.platform != "win32") and os.path.isfile(
os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "geojasper", geojasper)
):
geojasper = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "geojasper", geojasper)
a = os.popen(geojasper + " -f tmp.jp2 -F tmp.jpg")
a.close()
else:
jpg = MImage("tmp.jp2")
jpg.write("tmp.jpg")
try:
f = open("tmp.jpg", "rb")
input = f.read()
f.close()
except IOError, msg:
pass
示例8: crop
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def crop(request, block):
id = int(request.GET.get('id', -1))
data = json.loads(request.GET.get('data', []))
from core.models import File
file = File.objects.get(id=id)
file_crop_data = file.data.get('scale', {})
from pgmagick import Image, Geometry
file_path = '%s/%s' % (MEDIA_ROOT, file.path)
full_file_path = '%s/%s' % (file_path, file.file_name)
for crop_data in data:
#
# do not crop same image twice
#
if crop_data['name'] in file_crop_data:
local_crop_data = file_crop_data[crop_data['name']]
if 'scaled_width' in local_crop_data and 'scaled_height' in local_crop_data and 'crop_x' in local_crop_data and 'crop_y' in local_crop_data:
if local_crop_data['scaled_width'] == int(crop_data['scaled_width']) and local_crop_data['scaled_height'] == int(crop_data['scaled_height']) and local_crop_data['crop_x'] == int(crop_data['crop_x']) and local_crop_data['crop_y'] == int(
crop_data['crop_y']):
continue
image = Image(str(full_file_path))
g = Geometry(int(crop_data['scaled_width']), int(crop_data['scaled_height']), 0, 0)
image.scale(g)
gc = Geometry(int(crop_data['width']), int(crop_data['height']), int(crop_data['crop_x']), int(crop_data['crop_y']))
image.crop(gc)
image.quality(100)
image.sharpen(1.0)
full_scaled_image_path = '%s/%s_%s' % (file_path, crop_data['prefix'], file.file_name)
image.write(str(full_scaled_image_path))
scale_data = dict(
width=int(crop_data['width']),
height=int(crop_data['height']),
scaled_width=int(crop_data['scaled_width']),
scaled_height=int(crop_data['scaled_height']),
crop_x=int(crop_data['crop_x']),
crop_y=int(crop_data['crop_y']),
center_x=crop_data['center_x'],
center_y=crop_data['center_y'],
quality=100,
sharpen=1.0,
prefix=crop_data['prefix'],
name=crop_data['name'],
cropped=True
)
file.data['scale'][crop_data['name']] = scale_data
file.save()
return dict(status='success', message='Image %s was successfully cropped.' % file.title, id=id)
示例9: test
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def test():
from pgmagick import Image, FilterTypes
im = Image( './chambres-deluxes-I/chambre-101-s-474.tif' )
im.quality( 100 )
im.filterType( FilterTypes.SincFilter )
im.scale( '100x100' )
im.sharpen( 1.0 )
im.write( 'output.jpg' )
示例10: get_sized_image
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def get_sized_image(filename, size):
if not os.path.exists(DIR):
os.mkdir(DIR)
cache_hash = sha1('{0}\0{1}'.format(filename, size)).hexdigest() + '.jpg'
cache_path = os.path.join(DIR, cache_hash)
if not os.path.exists(cache_path):
im = Image(filename.encode('utf-8'))
im.sample(size)
im.write(cache_path)
return '/'.join(PARTS + (cache_hash,))
示例11: resize2
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def resize2( srcFile="", destFile="", w=200,h=200 ):
blobData = Blob(open(srcFile).read())
if ( h != -1 ):
img = Image( blobData, Geometry(w, h))
img.scale("%dx%d!" % (w,h))
else:
img = Image( blobData )
img.scale("%dx!" % w )
img.profile("*",Blob())
img.write(destFile)
return "True"
示例12: resize0
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def resize0( srcFile="", destFile="", w=200 ):
img = Image(srcFile)
sw = img.columns()
sh = img.rows()
if ( sw > w ):
tw = w
th = sh*(float(w)/float(sw))
img.scale("%dx%d"%(tw,th))
img.profile("*", Blob())
img.write(destFile)
return "True"
示例13: process_images
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def process_images(subdir):
curr_dir = data_dir + subdir + '/'
counter = 1
files = os.listdir(curr_dir)
interval = int(len(files) / target)
for file in files:
if counter % interval == 0 and counter / interval <= target:
img = Image(curr_dir + '/' + file)
img.type(ImageType.GrayscaleType)
img.write(out_dir + subdir + str(counter / interval) + '.tif')
counter = counter + 1
示例14: resize10
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def resize10( srcFile="", destFile="", w=200 ):
img = Image( srcFile )
sw = img.columns()
sh = img.rows()
scale = sw*sh
if ( scale > w ):
tw = int(sw*((float(w)/float(scale))**0.5))
th = int(w/tw)
img.scale("%dx%d"%(tw,th))
img.profile("*",Blob())
img.write(destFile)
return "True"
示例15: convert_split
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import write [as 别名]
def convert_split(srcfile='', dstpath='', truefile='', split='3x3', w=100, h=100):
"""
目前仅用作封面频道
"""
srcfile = srcfile.encode("utf-8")
dstpath = dstpath.encode("utf-8")
truefile = truefile.encode("utf-8")
(sp_x, sp_y) = split.split('x')
(file_name, image_ext) = os.path.splitext(os.path.basename(srcfile))
cw = int(sp_x) * int(w)
ch = int(sp_y) * int(h)
t1 = time.time()
#生成封面列表图
re = myGraphicsMagick.convert_gif_thumbnail_frame0_g(srcfile=srcfile, dstfile=truefile, w=cw, h=ch,
need_return=False)
if re == True:
#切割方式为从图片的左上开始逐行切割
#目标图片文件名为:50d8059b1a822.11.jpg
blobData = Blob(open(srcfile).read())
try:
num = 0#图片输出的编号
for j in range(int(sp_y)):
if ( num >= ( int( sp_x )*int( sp_y ) - 1 ) ):
break
for i in range(int(sp_x)):
img = Image( blobData, Geometry(cw,ch) )
linePos = i * int(w)
colsPos = j * int(h)
#从指定的像素点进行裁剪
img.crop( Geometry(w,h,linePos, colsPos) )
destFilename = dstpath+'/%s.%d.%s' %( file_name,num,image_ext )
img.profile("*",Blob())
img.write( destFilename )
num = num + 1
t2 = time.time()
sys.stdout.writelines(datetime.now().strftime('%Y-%m-%d %H:%M:%S ')+"libconvert appName:%s ver:%s cmdSN:%s type:%s cmdData:%s command : convert_split srcfile:%s dstfile:%s runTime:%s\n" % ( proto.protocal['appName'],proto.protocal['ver'],proto.protocal['cmdSN'],proto.protocal['type'],proto.protocal['cmdData'], srcfile,dstfile,(t2-t1)) )
sys.stdout.flush()
return ret
except Exception as e:
sys.stderr.writelines(datetime.now().strftime('%Y-%m-%d %H:%M:%S ')+"libconvert_split %s %s srcfile:%s destFilename:%s\n" % (e.args, e.message, srcfile,destFilename))
sys.stderr.flush()
return 'False'
else:
return "False"
pass
return 'True'