IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Image to CSS

    Reverland (lhtlyy@gmail.com)发表于 2013-03-07 00:00:00
    love 0

    Image to CSS

    Warning: 我警告过了,浏览器弱爆了的就不要点开了= =。内存太小了就慎重打开= =

    眼残,竟然看到这种奇葩的演示

    看了看CSS源码,想起来可以用Python Image Library做一个generator。

    结果就真得做了一个……

    Codes

    #! /bin/env python
    # -*- coding: utf-8 -*-
    
    """
    Script to turn image into css
    """
    
    import Image
    import sys
    
    __author__ = "Reverland (lhtlyy@gmail.com)"
    
    
    def getcss(im):
        """docstring for get"""
        css = """position: absolute;
        top: 30px;
        left: 30px;
        width: 0;
        height: 0;
        box-shadow:
            """
        string = '%dpx %dpx 0px 1px rgb%s,\n'
        for y in range(0, im.size[1], 1):
            for x in range(0, im.size[0], 1):
                if im.size[1] - y <= 1 and im.size[0] - x <= 1:
                    string = '%dpx %dpx 0px 1px rgb%s;\n'
                color = im.getpixel((x, y))
                css += string % (x, y, color)
        return css
    
    
    def gethtml(css):
        """docstring for gethtml"""
        html = """
        
    %s">
    """ % css return html if __name__ == '__main__': filename = sys.argv[1] #outfile = sys.argv[2] im = Image.open(filename) ratio = 0.5 size = (int(ratio * im.size[0]), int(ratio * im.size[1])) im.thumbnail(size) html = gethtml(getcss(im)) print html # with open(outfile, 'wb') as f: # f.write(html)

    Demo

    点击显示图像

    意义?

    意义在于可能你会死机= =

    尝试复制看看?



沪ICP备19023445号-2号
友情链接