$PATH
中,查看$PATH
的方式: echo $PATH
,这里我是放到了/usr/local/bin下cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs && chmod +x /usr/local/bin/phantomjs
下面是官方的例子,我进行了一些小小的修改,允许执行宽和高,背景颜色,以及js的路径
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
def bar_chart() -> Bar:
c = (
Bar(init_opts=opts.InitOpts(width=width, height=height, bg_color="white", js_host=file_path))
.add_xaxis(["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"])
.add_yaxis("商家A", [114, 55, 27, 101, 125, 27, 105])
.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49])
.reversal_axis()
.set_series_opts(label_opts=opts.LabelOpts(position="right"))
.set_global_opts(title_opts=opts.TitleOpts(title="Bar-测试渲染图片"))
)
return c
make_snapshot(snapshot, bar_chart().render(), "bar.png")
pip3 install pillow
from PIL import Image
import os
def get_size(file):
# 获取文件大小:KB
size = os.path.getsize(file)
return size / 1024
def get_outfile(infile, outfile):
if outfile:
return outfile
dir, suffix = os.path.splitext(infile)
outfile = '{}-out{}'.format(dir, suffix)
return outfile
def compress_image(infile, outfile='', mb=150, step=10, quality=80):
"""不改变图片尺寸压缩到指定大小
:param infile: 压缩源文件
:param outfile: 压缩文件保存地址
:param mb: 压缩目标,KB
:param step: 每次调整的压缩比率
:param quality: 初始压缩比率
:return: 压缩文件地址,压缩文件大小
"""
o_size = get_size(infile)
if o_size <= mb:
return infile
while o_size > mb:
im = Image.open(infile)
im.save(outfile, quality=quality)
if quality - step < 0:
break
quality -= step
o_size = get_size(outfile)
return outfile, get_size(outfile)
Auto configuration failed
140149858578048:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libssl_conf.so): libssl_conf.so: cannot open shared object file: No such file or directory
140149858578048:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
140149858578048:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=ssl_conf, path=ssl_conf
140149858578048:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=ssl_conf
在centos中执行:
yum install -y bitmap-fonts bitmap-fonts-cjk
在ubuntu中执行:
sudo apt-get install -y xfonts-wqy
wget https://assets.pyecharts.org/assets/echarts.min.js
file_path = "{}/".format(os.path.dirname(os.path.abspath(__file__)))
Bar(init_opts=opts.InitOpts(width=width, height=height, bg_color="white", js_host=file_path)))
这里主要看你哪里用的init_opts这个参数,没有的话可以在实例化图像实例的时候加上这个参数
- 3.重新执行图片就生成出来了
Bar(init_opts=opts.InitOpts(width=width, height=height, bg_color="white", js_host=file_path)))
至此问题全部解决,Bingo.