带Imagemagi的Python

2024-04-16 17:15:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用ImageMagick库编写一个Python代码,它将获取一个输入图像,并输出一个在原始图像中心有一个大的表情符号的图像。每次运行代码时,都应该随机选择表情符号。在

虽然我可以放置一个特定的表情符号,但我想随机选择一个表情符号是很困难的。为此我写了一个代码:

import urllib2

from wand.image import Image
from wand.display import display


fg_url = 'http://emojidictionary.emojifoundation.com/img/emoji50.jpg'
bg_url = 'http://www.camp4joy.narod.ru/Na/Nature-259.jpg'

bg = urllib2.urlopen(bg_url)
with Image(file=bg) as bg_img:
    fg = urllib2.urlopen(fg_url)
    with Image(file=fg) as fg_img:
        bg_img.composite(fg_img, left=214, top=160)
    fg.close()
    display(bg_img)
bg.close()

Tags: 代码from图像imageimporthttpurlimg