当前位置: 首页 > news >正文

百度中搜到网站名字wordpress 删除 角色

百度中搜到网站名字,wordpress 删除 角色,陕西 汽车 网站建设,得到app创始人先看知乎上面的一个连接 用Python写过哪些【脑洞大开】的小工具#xff1f; 这个哥们通过爬气象网站的气象雷达图#xff0c;生成一个gif的动态图。非常有趣且很实用#xff0c;那咱也实现下。 我们先实现一个从GIF提取帧的代码 我们这有个gif代码如下#xff1a; from PIL…先看知乎上面的一个连接 用Python写过哪些【脑洞大开】的小工具 这个哥们通过爬气象网站的气象雷达图生成一个gif的动态图。非常有趣且很实用那咱也实现下。 我们先实现一个从GIF提取帧的代码 我们这有个gif代码如下 from PIL importImageimportsysdefprocessImage(infile):try: imImage.open(infile)exceptIOError:print (Cant load, infile) sys.exit(1) i0 mypaletteim.getpalette()try:while 1: im.putpalette(mypalette) new_im Image.new(RGBA, im.size) new_im.paste(im) new_im.save(image\\astr(i).png) i 1im.seek(im.tell() 1)exceptEOFError:pass #end of sequence processImage(source.gif) 生成效果从gif提取frame是不是很简单只需要一个PIL库搞定 但从frame生成gif就麻烦了因为我们使用的是py3网上一大堆代码用的是py2.*的 比如PythonMagick 、 images2gif 还有部分手写gif文件头部GIF89a调用帧palette、NETSCAPE2.0写入图像等你们都运行成功了为什么我没有运行成功呢 唉 python就是牛库如此之多虽然本人Py一般般但有前人为你写诗您只要尾行加句号就可以了。这里我说的是imageio 下载地址 https://pypi.python.org/pypi/imageio (Version:2.2.0 by 2017-05-25) importmatplotlib.pyplot as pltimportimageio,os images[] filenamessorted((fn for fn in os.listdir(.) if fn.endswith(.png)))for filename infilenames: images.append(imageio.imread(filename)) imageio.mimsave(gif.gif, images,duration1) OK gif生成了 imageio.help(gif)其实PIL自身也有一个save方法里面有一个‘save_all’ 参数意思就是save多个当format指定为gif时生成的便是gif的动画 from PIL importImage imImage.open(a0.png) images[] images.append(Image.open(a1.png)) images.append(Image.open(a2.png)) im.save(gif.gif, save_allTrue, append_imagesimages,loop1,duration1,commentbaaabb) 读取第一帧将第一个帧的像素设置为gif像素 python将png图片格式转换生成gif动画已经可以实现了但我们这里要实现的是获取气象雷达图生成GIF。 1.获取数据 获取数据我们使用pquery from pyquery importPyQuery as pq d pq(http://products.weather.com.cn/product/radar/index/procode/JC_RADAR_AZ9210_JB) DomTree d(#slideform #slide option)2.下载气象雷达png图 想这个用Image.open 直接打开url的文件路径就可以 images.append(Image.open(http://pi.weather.com.cn/i/product/pic/l/sevp_aoc_rdcp_sldas_ebref_az9210_l88_pi_20170621014800000.png)) 那肯定是失败的 Traceback (most recent call last): FileE:/project/test2/my.py, line 29, in images.append(Image.open(http://pi.weather.com.cn/i/product/pic/l/sevp_aoc_rdcp_sldas_ebref_az9210_l88_pi_20170621014800000.png)) FileC:\Python36\lib\site-packages\PIL\Image.py, line 2410, inopen fp builtins.open(filename, rb) OSError: [Errno22] Invalid argument: http://pi.weather.com.cn/i/product/pic/l/sevp_aoc_rdcp_sldas_ebref_az9210_l88_pi_20170621014800000.png 异想天开呀 imageio支持url文件路径 参考 http://imageio.readthedocs.io/en/latest/examples.html importimageioimportvisvis as vv im imageio.imread(http://upload.wikimedia.org/wikipedia/commons/d/de/Wikipedia_Logo_1.0.png) vv.imshow(im) 使用requests 库保存图片 importrequests r requests.get(http://pi.weather.com.cn/i/product/pic/l/sevp_aoc_rdcp_sldas_ebref_az9210_l88_pi_20170621014800000.png, timeout3) file open(b1.png, wb) sizefile.write(r.content) file.close()3.生成气象雷达GIF图 python 生成gif在上面我们已经说到两种方法一种是imageio 另一种是PIL自带save_all,这里我们直接写一个类封装方法 源码如下 #-*- coding: UTF8 -*- importrequestsfrom pyquery importPyQuery as pqimportos, sysimportimageiofrom PIL importImage天气预报.gif 生成class classweatherForecast():def __init__(self, weatherSite, path, endpng, savemodel): self.savemodelsavemodelif notos.path.exists(path): os.makedirs(path)defgetPic(self):获取资源 print(获取pic) dpq(weatherSite) DomTree d(#slideform #slide option) #获取DOM节点option 标签 num 100 for bigpic inDomTree.items(): pic bigpic.attr(bigpic) #获取bigpic 属性指 num 1self.download(pic,a str(num) .png) #下载pic print(pic下载成功共下载 str(num - 100) 个png) self.download(endpng,a1200.png) #下载end.png self.download(endpng, a1201.png) self.download(endpng,a1202.png) self.download(endpng,a1203.png)defdownload(self, url, fname):下载pic :return images sizesize0try: r requests.get(url, timeout3) file open(path fname, wb) sizefile.write(r.content) file.close()except:pass returnsizedefgetGIF(self):生成gifimages[]print(执行开始) self.getPic()#获取图片资源 filenames sorted(fn for fn in os.listdir(path) if fn.endswith(.png))if self.savemodel 1: #imageio方法 for filename infilenames: images.append(imageio.imread(pathfilename))print(执行conversion操作) imageio.mimsave(weather.gif, images, duration0.5, loop1) #duration 每帧间隔时间loop 循环次数 print(完成……)elif self.savemodel 2: #PIL 方法 imN 1 for filename infilenames:if imN 1: #执行一次 im的open操作PIL在保存gif之前必须先打开一个生成的帧默认第一个frame的大小、调色 im Image.open(path filename) imN 2images.append(Image.open(pathfilename))print(执行conversion操作) im.save(weather.gif, save_allTrue, append_imagesimages, loop1, duration500, commentbthis is my weather.gif)print(完成……)注loop循环次数在浏览器有效果用看图软件不起作用 if __name__ __main__: weatherSite http://products.weather.com.cn/product/radar/index/procode/JC_RADAR_AZ9210_JB #上海南汇 path images/ #png 图片存储位置 endpng http://images.cnblogs.com/cnblogs_com/dcb3688/982266/o_end.png #因gif是循环播放end png 区分新loop savemodel 1 #1imageio保存图片 2PIL保存图片 weatherForecast weatherForecast(weatherSite, path, endpng, savemodel) weatherForecast.getGIF() sys.exit() 也可以修改gif尺寸大小先修改png大小 defdownload(self, url, fname):下载pic :return images sizesize0try: r requests.get(url, timeout3) file open(path fname, wb) sizefile.write(r.content) file.close()#修改图片大小原x640*y480 320*240 ima Image.open(path fname) (x, y) ima.size #read image size x_s 320y_s int((y * x_s) / x) ##calc height based on standard width out ima.resize((x_s, y_s), Image.ANTIALIAS) #resize image with high-quality out.save(path fname)except:pass return size images目录生成气象雷达图gif4.外部访问气象雷达图 脚步写好了如何让别人也能访问呢直接仍到公网IP的website目录就行了然后写一个crontab定时脚步每5分钟生成一次 */5 * * * * python /home/wwwroot/www/web/static/weather/weather_forecast.py #每5分钟执行天气查询脚本 在这里如果执行crontab定时脚步代码生成的gif就要指定位置否则生成的gif会在/root 目录里面 imageio.mimsave(/home/wwwroot/www/web/static/weather/weather.gif, images, duration0.5, loop1) # duration 每帧间隔时间loop 循环次数
http://www.huolong8.cn/news/191926/

相关文章:

  • 内蒙古城乡建设厅网站资质公告企业文化建设网站
  • 淮南学校网站建设电话广西建设银行行号查询网站
  • 启动网站集约化建设企业网站建设 毕业设计
  • 判断网站的好坏温州微网站制作电话
  • 需要做网站建设的公司数码网站建设总体目标
  • 上海做网站品牌公司高级网页设计师证书
  • 申请备案网站空间网站优化基本技巧
  • 浩博建设集团网站贵州今天刚刚发生的新闻
  • 网站建设与制作教学计划wordpress5.0改进
  • 天津非常好的网站建设wordpress 获取内容
  • 广东南方建设工程有限公司网站网站建设前期规划方案范文
  • 广州网站建设信科便宜高端建材项目
  • 怎么做学校官方网站做网站里面的图片像素要求
  • 网站开发是什动画制作物语
  • 正规网站优化公司网站建设域名的选取有讲究
  • 做海淘是在哪个网站上海网页设计公司哪家最好
  • 如何夸奖一个网站做的好微信小程序开发教程从零开始
  • 建设电子商务网站考核试卷wordpress 仿 主题
  • 旅游网站开发说明书如何建设网站视频
  • 搜索引擎怎么收录网站深圳市网站建设制作设计品牌
  • 网站建设与维护就业怎么样足球世界排名前十
  • 群晖 做网站怎么提高网站收录
  • 设计网站建设方案汕头
  • 建站之星app找平台推广
  • 深圳推荐企业网站制作维护微商分销商城
  • 方城企业网站制作哪家好wordpress没有安装主题
  • 引航博景做的网站公司装修费用可以一次性入账吗
  • 方法网站目录企业网站模板下载软件
  • seo整站优化外包哪家好wordpress 调用缩略图
  • 网站挂马黑链检测清除工具一般网站系统并发量