zoukankan      html  css  js  c++  java
  • python basemap画图去除图片的边边,把图片改为透明色

    # 去除图片的边边
    ax = fig.add_axes([0.1, 0.1, 0.7, 0.7]) ax.axis('off') plt.gca().xaxis.set_major_locator(plt.NullLocator()) plt.gca().yaxis.set_major_locator(plt.NullLocator()) plt.subplots_adjust(top=1, bottom=0, left=0, right=1, hspace=0, wspace=0) plt.margins(0, 0) plt.savefig(out_file, transparent=True, bbox_inches='tight', dpi=300, pad_inches=0.0, set_visiable=False)
    from PIL import Image
    
    # 图片改为透明色
    
    img = Image.open(new_file)
    img = img.convert("RGBA")
    datas = img.getdata()
    newData = []
    for item in datas:
        if item != (255, 255, 255, 0):
             pass
        if item[0] == 255 and item[1] == 255 and item[2] == 255:
             newData.append((255, 255, 255, 0))
        else:
             newData.append(item)
    img.putdata(newData)
    img.save('out_file.png', "PNG")
  • 相关阅读:
    运算符
    格式化输出
    while循环
    if 判断语句
    Swift # 字典
    Swift # 数组
    Swift # 字符串
    [ Swift # 函数 ]
    [ Bubble Sort ]& block
    数据结构 # 二叉树/堆/栈
  • 原文地址:https://www.cnblogs.com/luochunxi/p/13541160.html
Copyright © 2011-2022 走看看