使用Google App Engine和Python合并两张图片?

5
我希望将两张图片合并,并且在第一张图片的特定位置进行合并。
例如: 第一张图片:x.png(400 X 400px) 第二张图片:y.png(位于100,100坐标处)
我该如何使用Python在Google AppEngine上实现这个功能?
如果您能提供相关代码或参考资料,将不胜感激。
谢谢, 如果需要更多解释,请告诉我。
3个回答

13

你可以使用一个非常简化的图像库,它模拟了PIL的某些功能来完成这个任务。你所需要的函数是composite

from google.appengine.api import images

xpng = #Load data from x.png here, or read from BlobProperty
ypng = #Load data from y.png here, or read from BlobProperty

composite = images.composite([(xpng, 0, 0, 1.0, images.TOP_LEFT),
    (ypng, 100, 100, 1.0, images.TOP_LEFT)], 400, 400)

#composite now holds your new image data, to do what you want with

2

1
你可以查看Google Images API中的复合模块。如果它不起作用,这也值得一试。这是使用Python中的Image模块。
import Image
image1 = Image.open("#imageurl")
iamge2 = Image.open("#imageurl")

image1.paste(image2, (0, 0), image2)

1
不行,你不能直接在App Engine中使用PIL。你只能使用App Engine的图像API(或者,如果你能找到的话,使用纯Python代码来操作图像)。 - Wooble

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接