对于微信之前写过以下文章,有趣味能够点击查看:

如何导出你的微信语音

c 盘空间又满了?微信清理神器帮你开释空间

微信撤回的音讯也能看到!

如何备份可能被删的公众号文章和网页

如何在电脑上登陆多个微信

如何发一条空白的朋友圈

那些你可能不晓得的微信奇技淫巧

一键生成你的微信社交数据报告

你可能在朋友圈看过九宫格图片(把一张图片依照比例分成九份),就像这样的:

还有微博九宫格图 https://weibo.com/2717930601/... :

这种九宫格图片怎么发的呢?上面用Python搞定它,Python是门很简略实用的语言,即便不做开发工作也能够学习下,比方之前的下载抖音 一键批量下载抖音无水印视频 ,下载公众号文章一键下载公众号所有文章,导出文件反对PDF,HTML,Markdown,Excel,chm等格局 都是用的Python,之后我会写一篇如何应用Python来抓取数据,代码非常简单,只有你意识英文字母就会用。

PIL解决图片

先用pip装置切割图片的库 PIL pip install Pillow , 而后编辑代码:

from PIL import Image,ImageSequence,ImageFilterpic = input("请输出图片文件名:")im = Image.open(pic)width = im.size[0]//3height = im.size[1]//3x = 0y = 0filename = 1#保留的文件名for i in range(3):    for j in range(3):        crop = im.crop((x, y, x+width, y+height))        crop.save(str(filename) + '.jpg')        x += width        filename += 1    x = 0    y += height

间接命令行执行 python pic.py ,输出图片文件名即可在本地生成9张小图。

还能够将代码打包为exe可执行文件,这样不必装置Python就能够运行了。

pyinstaller 打包exe

打包用的工具是pyinstaller,先pip install pyinstaller装置它,而后pyinstaller -F pic.py ,不过我运行的时候出错了。

    for real_module_name, six_module_name in real_to_six_module_name.items():AttributeError: 'str' object has no attribute 'items'

谷歌了下须要升级库。

 pip install -U setuptoolsCollecting setuptools  Downloading https://files.pythonhosted.org/packages/6d/ed/52e05469314a266f68d9f251a8c1ab7a21a03327b1724056e3eea654bfd1/setuptools-50.0.3-py3-none-any.whl (784kB)Installing collected packages: setuptools  Found existing installation: setuptools 41.2.0    Uninstalling setuptools-41.2.0:      Successfully uninstalled setuptools-41.2.0Successfully installed setuptools-50.0.3pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple# 更新pip版本python -m pip install -U pip pip uninstall enum34Uninstalling enum34-1.1.6:  Would remove:    d:\python\lib\site-packages\enum34-1.1.6.dist-info\*    d:\python\lib\site-packages\enum\*Proceed (y/n)? y  Successfully uninstalled enum34-1.1.6"""    

再次执行pyinstaller -F pic.py 终于胜利了,不过生成的exe文件有点大(20多MB,公众号后盾回复 朋友圈 获取exe文件),双击exe文件输出文件名就能够运行了。 https://www.lanzoux.com/iWtJN...

60106 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.60112 INFO: Bootloader d:\python\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe60114 INFO: checking EXE60115 INFO: Building EXE because EXE-00.toc is non existent60115 INFO: Building EXE from EXE-00.toc60115 INFO: Appending archive to EXE d:\download\dist\pic.exe60279 INFO: Building EXE from EXE-00.toc completed successfully.

PIL除了切割图片还能够对照片去色。

img = Image.open("jay.jpg")img2 = img.convert("L")img2.save("jay2.jpg")

去色效果图:

对照片旋转90度。

img3 = img.rotate(90)img3.save("jay_rotate.jpg")

旋转效果图:

对照片翻转。

img4 = img.transpose(Image.FLIP_LEFT_RIGHT)img4.save("jay_transpose.jpg")

翻转效果图,周杰伦七里香几个字翻过来了:

除了应用Python 也有在线工具和微信小程序能够生成九宫格图片 https://www.dute.org/image-clip ,上传图片下载即可。

公众号 苏生不惑