Icon class生成器(Python)

先说起因,项目中有很多图标,需要把美工给的三种尺寸的png加工成class来用,这样的好处就不必说了。但是图标数量比较大,以后换肤的时候,更是纯搬砖的活,写了个脚本来解放一下以后写icon的class的搬运工。

搬砖步骤:

  1. 所有的icon的一倍图片,与本脚本放到一起(全部英文命名)

    • 图片命名与class一致,对应三种尺寸标记为1,2,3号.所有图片存储位置为:src/public/assets/images.
    • class命名: 图标名称+图标状态(N:normal;O:on;C:click;D:disable)
    • 使用者不关心图片大小.(^o^)/~
    • 注:图标最多有4种情况,个别图标可能不足4种,请勿强求.
  2. 运行脚本

    • python iconClass.py
  3. 将输出的内容copy到一个可以格式化的地方(比如webstream)

  4. 格式化一下,然后利用全局替换,把图片路径换一下。

  5. 最后结构:
/*以下参照UI20161220提供的图标*/@media all and (max-width: 1280px) {/*置顶*/.putTopN {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopN1.png) no-repeat;background-size: 100% 100%;}.putTopN:hover {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopC1.png) no-repeat;background-size: 100% 100%;}.putTopC {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopC1.png) no-repeat;background-size: 100% 100%;}.putTopD {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopD1.png) no-repeat;background-size: 100% 100%;}
}@media all and (min-width: 1280px) and (max-width: 1920px) {/*置顶*/.putTopN {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopN2.png) no-repeat;background-size: 100% 100%;}.putTopN:hover {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopC2.png) no-repeat;background-size: 100% 100%;}.putTopC {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopC2.png) no-repeat;background-size: 100% 100%;}.putTopD {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopD2.png) no-repeat;background-size: 100% 100%;}
}@media all and (min-width: 1920px) {/*置顶*/.putTopN {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopN3.png) no-repeat;background-size: 100% 100%;}.putTopN:hover {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopC3.png) no-repeat;background-size: 100% 100%;}.putTopC {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopC3.png) no-repeat;background-size: 100% 100%;}.putTopD {display: inline-block;width: 18px;height: 18px;background: url(../images/putTopD3.png) no-repeat;background-size: 100% 100%;}
}

附源码

# coding: utf8
import os
from PIL import Image
# 获取指定图片的长和宽
def imgSize(imgPath):img = Image.open(imgPath)return img.size# 获得.png的图片
def judjepng(filename):if os.path.isfile( filename ):a,b = os.path.splitext( filename )if b == ".png":return 1;else:return 0;def getFileList( p ):p = str( p )if p=="":return [ ]if p[ -1] != "/":p = p+"/"a = os.listdir( p )b = [ x   for x in a if judjepng( p + x )==1 ]return bpath = os.getcwd();
imgPaths = getFileList( path )
for imgPath1 in imgPaths:a,b = os.path.splitext( imgPath1 )imgsize = imgSize(imgPath1)classname = "." + a[:-1] +"{display: inline-block;width: "+str(imgsize[0])+"px;height: "+str(imgsize[1])+"px;background: url(../images/"+ a +".png) no-repeat;background-size: 100% 100%;}"print classname

补充:

    classname = "." + a[:-2] +"N:hover{display: inline-block;width: "+str(imgsize[0])+"px;height: "+str(imgsize[1])+"px;background: url(../images/"+ a +".png) no-repeat;background-size: 100% 100%;}"#   classname = "." + a[:-1] +"{display: inline-block;width: "+str(imgsize[0])+"px;height: "+str(imgsize[1])+"px;background: url(../images/"+ a +".png) no-repeat;background-size: 100% 100%;}"#   print " <td><span class=\" "+ a[:-1] + "\"></span></td><td>" + a[:-1] + "</td>"print classname

Icon class生成器(Python)相关推荐

  1. python的英文单词表_随机单词生成器 - Python

    所以我基本上是在一个项目中,计算机从单词列表中抽出一个单词,并为用户乱七八糟.只有一个问题:我不想不断地在列表中写很多单词,所以我想知道是否有一种方法可以导入大量的随机单词,所以即使我不知道它是什么, ...

  2. python代码图片头像_GitHub - nonPointer/avatar_generator: 头像图片生成器 Python代码

    avatar_generator 哈希头像图片生成器 Python代码 Identicon 在很多大型IT网站上可以见到,比如 Github, Sourceforge, Stackoveflow 等等 ...

  3. github 头像生成 java_GitHub - haoziiy/avatar_generator: 头像图片生成器 Python代码

    avatar_generator 哈希头像图片生成器 Python代码 Identicon 在很多大型IT网站上可以见到,比如 Github, Sourceforge, Stackoveflow 等等 ...

  4. AI智能文章生成器python仿文案狗AI文章写作

    近期有朋友想要一款AI智能写作软件,需求根据关键词或标题自行生成一篇文章,今天家兴网络免费分享给大家一款用python写的机器人训练智能写作软件! 据传这款软件是清华大学-计算机系某位学生写的,家兴网 ...

  5. 论文生成器python_一本道生成器Python版,笑喷了

    今天皮一下,众所周知,一本道是一本正经的胡说八道的简称,想必写过议论文的小伙伴,都知道引经据典是议论文高分必备,套上名人的话更加具有说服力是语文老师必教的知识点. 所以呢,今天介绍的这个生成器就走的是 ...

  6. 营销号废话生成器-python

    营销号废话生成器 深受其害 先弄个简单版,有空再试试"长篇大论" feihuas = ['是怎么回事呢?','相信大家都很熟悉,但是','是怎么回事呢,下面就让小编带大家一起了解吧 ...

  7. python随机生成列表_随机词生成器-Python

    所以我基本上是在一个项目中,计算机从单词列表中提取一个单词,然后为用户弄乱它. 只有一个问题:我不想继续在列表中写很多单词,所以我想知道是否有一种方法可以导入很多随机单词,所以即使我也不知道它是什么, ...

  8. python编写程序输出诗句_Python文本处理简介:44行代码编写一个简单的隐藏诗生成器,python,入门,藏头诗...

    想必最近大家家庭群里最近都会看到这么一张图: 一惊,这什么玩意儿???后来一搜会发现里面不同的诗句来自于不同的古诗,嘛,这不是很好玩的一件事情吗?这次我们使用Github的唐诗宋词dataset:ht ...

  9. 完全理解 Python 迭代对象、迭代器、生成器(转)

    完全理解 Python 迭代对象.迭代器.生成器 本文源自RQ作者的一篇博文,原文是Iterables vs. Iterators vs. Generators » nvie.com,俺写的这篇文章是 ...

最新文章

  1. Bundle Adjustment原理及应用(附实战代码)
  2. 华为汪涛:打造全场景智能联接解决方案,共建行业智能体
  3. SecureCRT中的实用配置
  4. 快学Scala习题解答—第二章 控制结构和函数
  5. Python数据类型之元祖
  6. php 如何将100w级的数据入库。
  7. linux打开文件系统调用,Linux2.4打开一个文件的系统调用
  8. Leetcode题目解答汇总
  9. html鼠标右键代码,Html鼠标右键菜单代码
  10. nodejs 截断字符串_JS对于字符串的切割截取
  11. VxWorks6.8串口示例
  12. 外包公司到底能不能选择
  13. 数字信号处理DFT实验二
  14. php小程序地图处理,微信小程序地图 map
  15. 博客右下角的动态人物(live2d)看板娘
  16. 数据结构—查找(第八章)
  17. 查询话费余额php接口,PHP代码示例_PHP账号余额查询接口 | 微米-中国领先的短信彩信接口平台服务商...
  18. 优惠券使用条件全解析
  19. linux Qt 复制文件至剪切板
  20. android五子棋源代码,Android五子棋游戏源码详解

热门文章

  1. schema约束文档与xml文件详解
  2. Err Welcoe to emergency mode
  3. FreeBsd网络性能优化方案sysctl
  4. 深度学习工作机制通俗介绍
  5. jQuery获取所有父级元素及同级元素及子元素的方法
  6. 雅虎欲出售核心业务 忠诚用户何去何从
  7. 后台(27)——文件上传
  8. Rails当你运行一个数据库回滚错误:ActiveRecord::IrreversibleMigration exception
  9. 仿Office的程序载入窗体
  10. vim的巧用---对比操作