本文整理汇总了Python中pgmagick.Image.density方法的典型用法代码示例。如果您正苦于以下问题:Python Image.density方法的具体用法?Python Image.density怎么用?Python Image.density使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmagick.Image
的用法示例。
在下文中一共展示了Image.density方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_jpgs
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import density [as 别名]
def to_jpgs(self, size='mid', pages=None):
""" Convert pdf to jpeg images
pages: array for pages, None for extract all
"""
dendic = dict(thumb=40, mid=100, big=150)
density = dendic[size]
pages = np.arange(0, self.pages, 1) if pages is None else pages
if len(pages) < 1:
return
sp = self.slides_path(size)
if os.path.exists(sp):
shutil.rmtree(sp)
os.makedirs(sp)
img = Image()
img.density("{}".format(density))
for page in pages:
if page > self.pages or page < 0:
continue
pdf = "{}[{}]".format(self.pdf_path, page)
slid = "{}/{:03d}".format(sp, page)
img.read(pdf)
img.write("{}.jpg".format(slid))
示例2: buildNodeImage
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import density [as 别名]
def buildNodeImage(self,node):
self.buildCounterNode+=1
node['name'] = node['name'].encode("utf-8")
print "{0:.2f}".format(self.buildCounterNode / (self.buildCounterNodeTotal) * 100)," percent complete of this batch \r",
scale = self.scaleFactor
#if node['size'] > 10:
#cale = 4.75
#if node['size'] < 900:
# scale = 4
circleHeight = int(float(node['size'])*scale)
circleWidth = int(float(node['size'])*scale)
canvasHeight = int(circleHeight *2)
canvasWidth = int(circleWidth* 2)
im = Image(Geometry(10,10), 'transparent')
fontsize = self.returnFontSize(canvasHeight)
im.fontPointsize(fontsize)
tm = TypeMetric()
im.fontTypeMetrics(node['name'], tm)
if tm.textWidth() > canvasWidth:
canvasWidth = int(tm.textWidth()) + 5
im = Image(Geometry(canvasWidth,canvasHeight), 'transparent')
im.density("72x72")
im.magick('RGB')
im.resolutionUnits(ResolutionType.PixelsPerInchResolution)
im.strokeAntiAlias(True)
color = (node['rgb'][0],node['rgb'][1],node['rgb'][2])
color = self.rgb_to_hex( color )
im.fillColor(color);
im.strokeWidth(2);
if circleWidth <= 20:
im.strokeColor("transparent");
else:
im.strokeColor("black");
if circleWidth <= 50:
im.strokeWidth(1);
circle = DrawableCircle( canvasWidth/2 , canvasHeight/2, (canvasWidth/2) + (circleWidth/2), (canvasHeight/2) + (circleHeight/2))
im.draw(circle)
im.fillColor("white");
im.strokeColor("black");
im.strokeWidth(1);
fontsize = self.returnFontSize(canvasHeight)
im.fontPointsize(fontsize)
tm = TypeMetric()
im.fontTypeMetrics(node['name'], tm)
textWidth = tm.textWidth()
textHeight = tm.textHeight()
if fontsize <= 30:
im.strokeColor("transparent")
text = DrawableText((canvasWidth / 2) - (textWidth/2), canvasHeight/2 + 6 , node['name'])
im.draw(text)
im.write(self.dataCircles + str(node['id']) + '.png')