本文整理汇总了Python中PythonMagick.Image.backgroundColor方法的典型用法代码示例。如果您正苦于以下问题:Python Image.backgroundColor方法的具体用法?Python Image.backgroundColor怎么用?Python Image.backgroundColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PythonMagick.Image
的用法示例。
在下文中一共展示了Image.backgroundColor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: walk_menu
# 需要导入模块: from PythonMagick import Image [as 别名]
# 或者: from PythonMagick.Image import backgroundColor [as 别名]
def walk_menu(entry):
if isinstance(entry, xdg.Menu.Menu) and entry.Show is True:
map(walk_menu, entry.getEntries())
elif isinstance(entry, xdg.Menu.MenuEntry) and entry.Show is True:
# byte 1 signals another entry
conn.sendall('\x01')
img_path = icon_attr(entry.DesktopEntry).encode('utf-8')
if img_path and os.path.isfile(img_path):
try:
# Create an empty image and set the background color to
# transparent. This is important to have transparent background
# when converting from SVG
img = Image()
img.backgroundColor(Color(0, 0, 0, 0xffff))
img.read(img_path)
# scale the image to 48x48 pixels
img.scale(Geometry(48, 48))
# ensure the image is converted to ICO
img.magick('ICO')
b = Blob()
img.write(b)
# icon length plus data
conn.sendall(struct.pack('i', len(b.data)))
conn.sendall(b.data)
except Exception:
conn.sendall(struct.pack('i', 0))
else:
conn.sendall(struct.pack('i', 0))
name = entry.DesktopEntry.getName()
# name length plus data
conn.sendall(struct.pack('i', len(name)))
conn.sendall(name)
command = re.sub(' -caption "%c"| -caption %c',
' -caption "%s"' % name, entry.DesktopEntry.getExec())
command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', command)
if entry.DesktopEntry.getTerminal():
command = 'xterm -title "%s" -e %s' % (name, command)
# command length plus data
conn.sendall(struct.pack('i', len(command)))
conn.sendall(command)
示例2: pad_image_to_x480
# 需要导入模块: from PythonMagick import Image [as 别名]
# 或者: from PythonMagick.Image import backgroundColor [as 别名]
def pad_image_to_x480(file):
from PythonMagick import Image, CompositeOperator
fname = file.split(".")[0]
ext = file.split(".")[-1]
outfile = os.path.join(destdir, fname + "_" + "l" + ".jpg")
## Make BG layer
bgimg = Image('400x480', 'white')
## Open Primary image
img = Image(file)
img.backgroundColor("white")
img.sample('350x432')
# Composite + Save Primary over bg, padding primary with white of bg
type = img.type
img.composite(bgimg, 0, 0, CompositeOperator.DstOverCompositeOp)
img.magick('JPG')
img.type = type
img.quality(100)
img.write(outfile)