安徽兴罗建设集团网站wordpress用户信息修改

张小明 2026/1/7 7:20:49
安徽兴罗建设集团网站,wordpress用户信息修改,网站报错 自动404,南宁网站建设公司怎么赚钱目标与范围 将约 90MB 的 GIF 压缩到用户可控的目标体积#xff08;例如 --max-mb 10#xff09;在体积、清晰度、流畅度之间做平衡#xff0c;参数可调#xff08;分辨率、帧率、色彩数#xff09; 技术路线 使用 Python Pillow 读取/写入 GIF#xff08;与仓库中 writ…目标与范围将约 90MB 的 GIF 压缩到用户可控的目标体积例如--max-mb 10在体积、清晰度、流畅度之间做平衡参数可调分辨率、帧率、色彩数技术路线使用 Python Pillow 读取/写入 GIF与仓库中writerpillow一致避免额外依赖逐帧处理ImageSequence迭代帧、统一缩放、量化调色板、重写duration保存开启optimizeTrue并设置save_allTrue、disposal2以减少冗余数据压缩策略由轻到重渐进分辨率按--scale或--max-width/--max-height对所有帧统一缩放LANCZOS帧率按--target-fps对帧集合采样保持总时长基本不变通过调整每帧duration色彩数使用quantize将每帧降到128/64/32色必要时关闭抖动以进一步减小体积存储优化共享首帧调色板、optimizeTrue、disposal2减少重复像素记录自适应迭代若仍超出--max-mb依次降低色彩→降低帧率→进一步缩放直到达标程序设计新增脚本compress_gif.pyCLI 接口python compress_gif.py input.gif -o output.gif --max-mb 10 --scale 0.5 --fps 12 --colors 128仅给--max-mb时走自动模式按上述策略逐步压缩直至达标输出日志原/新大小、压缩比例、最终参数便于复现与调参依赖与环境依赖Pillow仓库已通过matplotlib的writerpillow间接使用环境Windows / Python 3.8不强制要求安装ffmpeg或gifsicle验证与评估使用你的 90MB GIF 实测打印压缩前后大小与关键参数确保肉眼观感可接受回归测试对draw_results_pareto.py生成的 GIF 进行压缩验证兼容性可选增强确认后可一并实现质量预设--preset {high,medium,low}映射到一组参数并行处理多进程量化以加速在 CPU 充足情况下外部工具检测到gifsicle时可选--use-gifsicle做二次优化交付物compress_gif.py脚本 简要 README 使用示例示例命令与压缩前后对比报告包含体积和主参数待确认的默认参数max_mb10、fps12、scale0.5、colors128如需不同目标体积或更高/更低质量告知我调整默认值后开始实现importargparseimportosimportmathimporttempfilefromPILimportImage,ImageSequencedef_resample_filter():try:returnImage.Resampling.LANCZOSexceptException:returnImage.LANCZOSdef_load_frames(input_path):imImage.open(input_path)frames[]durations[]forframeinImageSequence.Iterator(im):durationframe.info.get(duration,im.info.get(duration,100))ifframe.modein(RGBA,LA):bgImage.new(RGB,frame.size,(255,255,255))frameframe.convert(RGBA)bg.paste(frame,maskframe.split()[-1])framebgelse:frameframe.convert(RGB)frames.append(frame)durations.append(int(duration))iflen(durations)0:durations[100]*len(frames)returnframes,durationsdef_compute_fps(durations):ifnotdurations:return10.0avgsum(durations)/float(len(durations))ifavg0:return10.0return1000.0/avgdef_compute_scale(size,scale,max_width,max_height):w,hsize s1.0ifscaleisnotNone:smin(s,float(scale))ifmax_widthisnotNoneandw*smax_width:smin(s,float(max_width)/float(w))ifmax_heightisnotNoneandh*smax_height:smin(s,float(max_height)/float(h))smax(s,0.05)returnsdef_resize_frames(frames,scale,max_width,max_height):ifscaleisNoneandmax_widthisNoneandmax_heightisNone:returnframes resample_resample_filter()w0,h0frames[0].size s_compute_scale((w0,h0),scale,max_width,max_height)new_wmax(1,int(w0*s))new_hmax(1,int(h0*s))return[f.resize((new_w,new_h),resample)forfinframes]def_sample_frames(frames,durations,target_fps):iftarget_fpsisNone:returnframes,durations orig_fps_compute_fps(durations)iftarget_fpsorig_fps:returnframes,durations stepmax(1,int(math.ceil(orig_fps/float(target_fps))))new_frames[]new_durations[]acc0fori,(f,d)inenumerate(zip(frames,durations)):ifi%step0:new_frames.append(f)new_durations.append(accd)acc0else:accdifacc0andnew_durations:new_durations[-1]accreturnnew_frames,new_durationsdef_quantize_frames(frames,colors,dither):ifcolorsisNone:returnframes q[]d1ifditherelse0forfinframes:q.append(f.quantize(colorsint(colors),methodImage.MEDIANCUT,ditherd))returnqdef_save_gif(frames,durations,output_path):ifnotframes:raiseRuntimeError(no frames)firstframes[0]restframes[1:]iflen(frames)1else[]first.save(output_path,save_allTrue,append_imagesrest,optimizeTrue,durationdurations,loop0,disposal2)def_file_size_mb(path):returnos.path.getsize(path)/(1024.0*1024.0)defcompress_once(input_path,output_path,scaleNone,target_fpsNone,colorsNone,ditherTrue,max_widthNone,max_heightNone):frames,durations_load_frames(input_path)frames_resize_frames(frames,scale,max_width,max_height)frames,durations_sample_frames(frames,durations,target_fps)frames_quantize_frames(frames,colors,dither)_save_gif(frames,durations,output_path)return_file_size_mb(output_path)defcompress_auto(input_path,output_path,max_mb,init_scaleNone,init_fpsNone,init_colorsNone,ditherTrue,max_widthNone,max_heightNone):frames,durations_load_frames(input_path)orig_fps_compute_fps(durations)scaleinit_scaleifinit_scaleisnotNoneelse0.5colors_tiers[128,64,32,16]fps_tiers[12,10,8,6]colorsinit_colorsifinit_colorsisnotNoneelsecolors_tiers[0]fpsinit_fpsifinit_fpsisnotNoneelsemin(int(orig_fps),fps_tiers[0])tmp_pathNonetry:for_inrange(12):withtempfile.NamedTemporaryFile(suffix.gif,deleteFalse)ast:tmp_patht.name sizecompress_once(input_path,tmp_path,scalescale,target_fpsfps,colorscolors,ditherdither,max_widthmax_width,max_heightmax_height)ifsizemax_mb:os.replace(tmp_path,output_path)returnsize,{scale:scale,fps:fps,colors:colors,dither:dither}ifcolorscolors_tiers[-1]:forcincolors_tiers:ifcolorsc:colorscbreakcontinueiffpsfps_tiers[-1]:forfinfps_tiers:iffpsf:fpsfbreakcontinuescalemax(0.3,scale*0.85)os.replace(tmp_path,output_path)return_file_size_mb(output_path),{scale:scale,fps:fps,colors:colors,dither:dither}finally:iftmp_pathandos.path.exists(tmp_path):try:os.remove(tmp_path)exceptException:passdefgenerate_sample_gif(path):frames[]foriinrange(60):color((i*5)%255,128,(255-i*4)%255)frames.append(Image.new(RGB,(640,360),color))durations[50]*len(frames)frames[0].save(path,save_allTrue,append_imagesframes[1:],durationdurations,loop0,optimizeTrue,disposal2)defmain():pargparse.ArgumentParser()p.add_argument(input,nargs?,help输入 GIF 路径)p.add_argument(-o,--output,help输出 GIF 路径)p.add_argument(--max-mb,typefloat,defaultNone,help目标最大体积 MB)p.add_argument(--scale,typefloat,defaultNone,help缩放比例 0-1)p.add_argument(--fps,typeint,defaultNone,help目标帧率)p.add_argument(--colors,typeint,defaultNone,help色彩数量 256 以下)p.add_argument(--max-width,typeint,defaultNone,help最大宽度)p.add_argument(--max-height,typeint,defaultNone,help最大高度)p.add_argument(--no-dither,actionstore_true,help关闭抖动)p.add_argument(--self-test,actionstore_true,help生成示例 GIF 并压缩)argsp.parse_args()ifargs.self_test:test_inos.path.join(os.getcwd(),_sample.gif)test_outos.path.join(os.getcwd(),_sample_compressed.gif)generate_sample_gif(test_in)ifargs.max_mb:size,paramscompress_auto(test_in,test_out,max_mbfloat(args.max_mb),init_scaleargs.scale,init_fpsargs.fps,init_colorsargs.colors,dither(notargs.no_dither),max_widthargs.max_width,max_heightargs.max_height)else:sizecompress_once(test_in,test_out,scaleargs.scale,target_fpsargs.fps,colorsargs.colors,dither(notargs.no_dither),max_widthargs.max_width,max_heightargs.max_height)params{scale:args.scale,fps:args.fps,colors:args.colors,dither:(notargs.no_dither)}print(原始体积(MB),_file_size_mb(test_in))print(压缩体积(MB),size)print(参数,params)returnifnotargs.input:raiseSystemExit(缺少输入 GIF 路径或使用 --self-test)input_pathargs.inputoutput_pathargs.outputor(os.path.splitext(input_path)[0]_compressed.gif)ifargs.max_mbisnotNone:size,paramscompress_auto(input_path,output_path,max_mbfloat(args.max_mb),init_scaleargs.scale,init_fpsargs.fps,init_colorsargs.colors,dither(notargs.no_dither),max_widthargs.max_width,max_heightargs.max_height)print(原始体积(MB),_file_size_mb(input_path))print(压缩体积(MB),size)print(参数,params)print(输出,output_path)else:sizecompress_once(input_path,output_path,scaleargs.scale,target_fpsargs.fps,colorsargs.colors,dither(notargs.no_dither),max_widthargs.max_width,max_heightargs.max_height)print(原始体积(MB),_file_size_mb(input_path))print(压缩体积(MB),size)print(输出,output_path)if__name____main__:main()
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

怎么做能够让网站流量大沈阳整站优化

直播带货话术优化:基于竞品分析的AI建议系统 在直播间里,一句话能决定一场直播的成败。一个精准的情绪钩子、一句恰到好处的价格锚定,甚至是对用户痛点的一次共情回应,都可能直接撬动转化率的跃升。然而,大多数主播仍在…

张小明 2026/1/2 2:35:36 网站建设

上海 高端网站建设绍兴易网网站开发

博主介绍:✌️码农一枚 ,专注于大学生项目实战开发、讲解和毕业🚢文撰写修改等。全栈领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围:&am…

张小明 2026/1/5 20:12:03 网站建设

个人网站备案民宿预订网站制作

读取本地图像数据传递给多模态大模型进行处理并返回结果 读取本地图像数据传递给多模态大模型进行处理并返回结果 import base64 from openai import OpenAI from PIL import Image import io import os# # 配置 # API_BASE "http://192.168.8.221:9024/v1" MODEL…

张小明 2026/1/6 12:15:39 网站建设

网站设计与实现作业虎牙网页游戏大厅

如何用TensorRT镜像快速部署Llama 3、ChatGLM等热门模型? 在大语言模型(LLM)日益普及的今天,一个看似“能跑”的模型和真正“可用”的服务之间,往往隔着一条由延迟、吞吐量与硬件成本构成的鸿沟。比如你手头有个 Llama…

张小明 2026/1/2 2:35:38 网站建设

域名做违法网站单页的网站怎么做

地铁线路图可视化终极指南:基于WebGPU的高效绘制方案 【免费下载链接】transit-map The server and client used in transit map simulations like swisstrains.ch 项目地址: https://gitcode.com/gh_mirrors/tr/transit-map Transit Map是一款专业的地铁线路…

张小明 2026/1/1 4:27:07 网站建设

浙江金顶建设公司网站公司网页怎么修改

GPT-SoVITS与云端GPU结合:弹性算力助力快速模型训练 在AI语音技术飞速演进的今天,一个普通开发者仅用一部手机录下的60秒人声,就能训练出高度逼真的个性化语音模型——这不再是科幻场景。随着GPT-SoVITS这类少样本语音克隆系统的成熟&#xf…

张小明 2026/1/1 3:11:56 网站建设