无法通过PHP导入PIL

Santoshkumar Sunny
<?php
echo exec("python txt_img.py admin 2>&1");
highlight_file(__FILE__);
?>

php正在运行,服务器中没有任何问题,但是当我通过浏览器访问php时,显示错误ImportError:No module named'PIL'。python代码也正在运行,服务器中没有任何问题。

# desired size
import random
import sys
from PIL import Image, ImageDraw, ImageFont
img = random.randint(1,10)
image = Image.open(str(img)+'.jpeg')

# initialise the drawing context with
# the image object as background

draw = ImageDraw.Draw(image)
font = ImageFont.truetype('arial.ttf',100) 
# starting position of the message
(x, y) = (100,70)
name = sys.argv[1]  
color = 'rgb(0,0,0)'
draw.text((x, y), "Welcome "+name, fill=color,font=font)
# save the edited image
img= random.randint(1,10)
img = "greet_"+str(img)+".jpeg"
image.save(img)
print(img)

提前致谢。

加文

必须为当前用户或root用户安装PIL,这可以通过使用脚本本身,使用subprocess或通过以下命令安装来实现

sudo pip install pillow

对于较早版本的pip(<10)pip.main(['install', package])也可以使用,但是使用子过程是更安全的选择。

这只是一种骇人听闻的方法,必须有更好的解决方法。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章