吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 7292|回复: 49
收起左侧

[原创工具] 【Python】本地GIF图生成网页预览

  [复制链接]
onlyclxy 发表于 2021-4-10 14:10
本帖最后由 onlyclxy 于 2021-5-13 20:15 编辑

好久不见啊!这次做了一个好玩的!可以将文件夹里的图片生成一个网页预览,效果这样:

GIF4.gif


这样:
Snipaste_2021-04-10_13-32-26.jpg


这样:
Snipaste_2021-04-10_13-20-30.jpg


反正我可太喜欢这次做的这个小工具了!.
电脑里有很多Gif图, 电脑的缩略图只能生成静帧的预览图,而可以通过这个生成个网页,可以一下子预览全部的动态图了. 当然,也有个弊端,一次加载大量的gif到网页上, 会特别特别占内存,就需要一个大内存.不过这都2021年了.谁还没个十几二十几大几十几的内存嘞?
不过您内存要是真的没多大(比如电脑4g内存,2g内存), 一定慎重加载超多图片!!!


这次的创意. 来自获取了一堆Gif后,懒着懒着突然有的灵感!...这次软件特别好写, 要是有兄台想模仿或者二次创作, 请一定要艾特我呦!!!之前我写的一些原创, 有些被人模仿去了, 然没见艾特我的就很郁闷..有艾特的我的就超开心!


这回提供Python的源代码和生成好的exe文件. exe文件请到最下面的蓝奏云下载.


[Python] 纯文本查看 复制代码
import os
import traceback

def makeweb(xpath):    
    filespath=""
    contentfiles=[]
    try:        
        list_dirs = os.walk(xpath)
        for root, _dirs, files in list_dirs:             
            for f in files: 
                f=f.lower()
                bool1 = f.endswith(".gif")
                bool2 = f.endswith(".jpg")
                bool3 = f.endswith(".png")
                bool4 = f.endswith(".bmp")

                if bool1 or bool2 or bool3 or bool4:
                    shortpath=root[len(xpath)+1:len(root)]
                    if len(shortpath)>0:
                        filespath=shortpath+"\\"+f
                        contentfiles.append(filespath)      
                    else:
                        filespath=f
                        contentfiles.append(filespath)
            
        if len(contentfiles)>0:
   
            effecttype = os.path.basename(xpath)#带后缀的文件名
            #effecttype="火焰"
            filename = xpath+'\\'+effecttype+'.html'
            with open(filename, 'w',encoding="utf-8") as file_object:
                file_object.write("<!DOCTYPE html>\n")
                file_object.write("<html>\n")
                file_object.write("<title>"+effecttype+"</title>\n")
                file_object.write("<style type=\"text/css\">.left{float: left;}.pic {/*max-width: 300px;height:auto;*/max-height: 130px;width: auto;} </style>\n")
                file_object.write("<head><link rel=\"icon\" type=\"image/x-icon\" href=\""+contentfiles[0]+"\" /></head>\n")
                file_object.write("<body>\n")
                file_object.write("<h5>可以按住Ctrl + 鼠标滚轮 放大缩小页面,Ctrl + 0 重置页面</h5>\n")
                file_object.write("<h5>"+effecttype+"分类</h5>\n")   
                for i in contentfiles:
                    file_object.write("<div class=\"left\"><a href=\""+i+"\" target=\"_blank\"><img class=\"pic\" src=\""+i+"\" ></a></div>\n")
                file_object.write("</body>\n")                    
                file_object.write("</html>\n")    

        else:
            print("目标文件夹里没有图片文件(bmp,jpg,png,gif),请选择一个有这些图片类型的文件夹后重新生成网页")
            return False
        totalpath=xpath+"\\"+effecttype
        totalpath=totalpath.replace("\\\\","\\")
        print(totalpath+".html 网页制作完成")
        os.system("explorer /select, "+'\"'+filename+'\"')
    except Exception as _ex:
        print("程序出现错误,请把下面的错误复制给制作者用于修改,谢谢!")
        print("--------------------------------------------------------")
        print('traceback.format_exc():\n%s' % traceback.format_exc())
        print("--------------------------------------------------------")
        print(effecttype+"网页制作失败,请联系制作者")

if __name__ == '__main__':
    print("图片生成网页预览(gif,png,bmp,jpg)  吾爱破解论坛 52pojie.cn")    
    path=input("请粘贴或者拖拽一个图片文件夹的路径,用来生成网页:\r\n")
    while True:
        
        path=path.replace("\"", "")
        if os.path.exists(path):
            bool1 = path.endswith("\\")
            if bool1:
                path=path.strip('\\')
            makeweb(path)
        else:
            print("目标文件夹不存在,请重新选择一个有效的文件夹来生成图片网页")
        path=input("本次操作完毕,继续操作请再次粘贴或者拖拽一个图片文件夹的路径,结束请直接关闭本窗口:\r\n")





蓝奏云:
https://wwe.lanzoui.com/b01u4u4wh
密码:a1rm

免费评分

参与人数 16吾爱币 +22 热心值 +12 收起 理由
w123w666 + 1 谢谢@Thanks!
sliencely + 1 我很赞同!
nacess + 1 + 1 我很赞同!
落汤鸡 + 1 + 1 我很赞同!
fineconey + 1 + 1 谢谢@Thanks!
轻笑 + 1 + 1 谢谢@Thanks!
刘大富 + 1 我很赞同!
lbwnba + 1 + 1 谢谢@Thanks!
hwxq43 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
yanglinman + 1 谢谢@Thanks!
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
ltzy19303 + 1 + 1 谢谢@Thanks!
FineDrops + 1 + 1 热心回复!
流浪星空 + 1 我很赞同!
今晚吃dian啥 + 1 + 1 谢谢@Thanks!
baicai12138 + 2 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

d8349565 发表于 2022-3-21 12:50
onlyclxy 发表于 2022-3-21 10:42
要是简单页面. 图片数量少还好
我这边好几个G的GIF一起加载到内存上. 得等半天..

其实和你的代码逻辑是一样的,速度差不多呢,只是相对代码少一些
文件结构


[Python] 纯文本查看 复制代码
from flask import *
import os
app._static_folder = "./templates/static"
app = Flask(__name__)
files_path = [f'../static/images/{os.path.basename(file)}' for file in os.scandir('static/images') if '.gif' in os.path.basename(file)]

@app.route('/')
def index():
    files_path = [f'../static/images/{os.path.basename(file)}' for file in os.scandir('static/images') if
                  '.gif' in os.path.basename(file)]
    return render_template('/index.html',files_path = files_path)
if __name__=="__main__":
    app.run()


[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .pic{
            height: 200px;
        }
    </style>
</head>
<body>
    {%for path in files_path%}
    <img src={{path}} alt="1" class="pic">
    {% endfor %} 

</body>
</html>
 楼主| onlyclxy 发表于 2022-3-21 13:37
d8349565 发表于 2022-3-21 12:50
其实和你的代码逻辑是一样的,速度差不多呢,只是相对代码少一些
文件结构

握爪握爪.
另外   我后来想搞那种瀑布流的来着, 就是那种往下滚会自动加载的 .而不是说一次性全加载完.
(最好是页面滚到哪.就显示哪里的图片,看不见已经加载的图片清理内存)
然后就搞不定了. 虽然说有模板... 也没弄成了..也不知道本地这种网页能不能搞成.
cherrypi 发表于 2021-4-10 14:36
kli2021 发表于 2021-4-10 14:50
好东西,可惜很早以前就把好玩的gif全转mp4了
ltzy19303 发表于 2021-4-10 15:58
好玩。下载来试试。感谢分享
筱柒网络 发表于 2021-4-10 16:36
好东西,以前建站做过这种
 楼主| onlyclxy 发表于 2021-4-10 16:58
kli2021 发表于 2021-4-10 14:50
好东西,可惜很早以前就把好玩的gif全转mp4了

视频其实比gif省地方 一个gif可大了 视频就可以压缩到特别小  省硬盘还得是视频
头像被屏蔽
hwxq43 发表于 2021-4-11 03:42
提示: 作者被禁止或删除 内容自动屏蔽
alexeyesgz 发表于 2021-4-11 04:45
支持一下,应该好用 谢谢
lenovogoto 发表于 2021-4-11 08:00
学习了,谢谢楼主
wh1969 发表于 2021-4-11 08:51
这个小工具实用,果断评分
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-26 10:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表