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

网站建设的项目方案模板wordpress图片调用代码

网站建设的项目方案模板,wordpress图片调用代码,禄劝彝族苗族网站建设,有哪些ui的设计网站最近同事经常找我帮她打印试卷#xff0c;很奇葩的是#xff0c;她的试卷都是*红书上下载的图片#xff0c;一张张打印不好看#xff0c;而且可能打印不完全#xff0c;大小也不协调#xff0c;所以有了这个脚本。 【需要给小孩打印图片格式的试卷时也比较实用】 -----…最近同事经常找我帮她打印试卷很奇葩的是她的试卷都是*红书上下载的图片一张张打印不好看而且可能打印不完全大小也不协调所以有了这个脚本。 【需要给小孩打印图片格式的试卷时也比较实用】 --------------------------------------------------------------------------------------------------------------------------------- 使用方法 方法一直接将脚本放到图片文件夹内并运行脚本 方法二命令行运行 命令行参数 python convert_images_to_pdf.py [图片文件夹路径] [PDF保存路径]  图片文件夹路径可选默认为python脚本所在目录  PDF保存路径可选默认路径为 图片文件夹路径 文件名为图片文件夹名.PDF。需先指定图片文件夹路径后再指定PDF保存路径 --------------------------------------------------------------------------------------------------------------------------------- 命令行示例 假设脚本名为convert_images_to_pdf.py只指定图片目录 python convert_images_to_pdf.py C:\img_folder 同时指定图片目录和pdf路径  python convert_images_to_pdf.py C:\img_folder  D:\result.pdf 代码 # -*- coding: utf-8 -*-import os import subprocess import sysfrom PIL import Image from reportlab.lib.pagesizes import letter from reportlab.pdfgen import canvasdef pause_exit():subprocess.run(pause, shellTrue)exit()def get_images(img_folder):遍历目录获取目录下所有的图片img_format (.jpg, .png, .bmp)images []for file_name in os.listdir(img_folder):if file_name.lower().endswith(img_format):images.append(os.path.join(img_folder, file_name))return sorted(images)def get_image_size(img_file, page_width, page_height):设置每个图片的大小with Image.open(img_file) as img:img_width, img_height img.sizeif img_height page_height * 0.95 or img_width page_width * 0.95:height_scale (page_height * 0.95) / img_heightwidth_scale (page_width * 0.95) / img_widthscale min(height_scale, width_scale)img_width * scaleimg_height * scalereturn img_width, img_heightdef create_pdf(pdf_file, images, page_width, page_height):创建 pdf 文件并添加图片c canvas.Canvas(pdf_file, pagesizeletter)total_images len(images)for i, img_path in enumerate(images):img_width, img_height get_image_size(img_path, page_width, page_height)x (page_width - img_width) / 2y (page_height - img_height) / 2c.drawImage(img_path, x, y, img_width, img_height)c.showPage()progress_bar(i 1, total_images)c.save()def create_pdf_from_path(img_folder, pdf_fileNone):遍历给定路径将路径下的图片添加进pdf并将pdf保存在指定路径下images get_images(img_folder)if images:if not pdf_file:pdf_name os.path.basename(img_folder) .pdfpdf_file os.path.join(img_folder, pdf_name)page_width, page_height lettercreate_pdf(pdf_file, images, page_width, page_height)return pdf_fileelse:print(f{img_folder} 下没有图片当前支持的图片格式为 jpg、png 和 bmp)pause_exit()def progress_bar(current, total, bar_length60):进度条filled_length int(bar_length * current // total)bar * filled_length - * (bar_length - filled_length)percent current / total * 100sys.stdout.write(f\r处理进度|{bar}| {percent:.2f}%)sys.stdout.flush()if __name__ __main__:subprocess.run(title 目录内图片转PDF, shellTrue)try:(*rest,) sys.argv[1:]if not rest:img_folder os.getcwd() # 使用当前文件夹作为 img_folderpdf_file Noneelse:img_folder, *pdf_file restpdf_file pdf_file[0] if pdf_file else Noneexcept ValueError:print(请提供图片文件夹路径作为参数)pause_exit()if not os.path.exists(img_folder):print(f{img_folder} 路径不存在)pause_exit()elif not os.path.isdir(img_folder):print(f{img_folder} 不是一个文件夹)pause_exit()else:pdf_file create_pdf_from_path(img_folder, pdf_file)if pdf_file:subprocess.run([explorer, pdf_file])else:pause_exit()
http://www.hkea.cn/news/14408132/

相关文章:

  • 包头网站建设公司哪家好最适合新人的写作网站
  • 网站信息网上商城网站设计和实现
  • 网站管理 官网微信公众平台开发者是什么
  • 网站建设相关视频教程网站建设的一些问题
  • 网站开发 php模板网站搭建公司排名
  • ps怎么做网站页面oa管理系统免费版
  • 一般设计网站页面用什么软件做绘图软件免费版
  • 专业的网页设计服务seo综合查询工具可以查看哪些数据
  • php初学者网站网站自己怎么做直播
  • 在哪个网站做流动补胎的广告好企业宣传片策划制作
  • 南昌 网站 公司类似凡科建站的平台
  • 青岛高品质网站建设网站建设的实施制作阶段包括
  • 黑龙江省建设教育网站建设部住房城乡建设厅网站
  • wordpress 增加站长统计哪个平台电商运营比较好
  • 制作网站公司谁家好哪些网站使用wordpress
  • 刘金鹏做网站快速排名优化推广价格
  • wordpress子目录建站怎么选择主题快速搭建论坛
  • 定制企业网站有哪些为什么网站要用外链
  • 宁波网站制作设计分销电商平台有哪些
  • 聊城网站开发公司中铁建设集团有限公司招标网
  • 开发app和微网站有哪些id注册网站
  • aliyun怎么建网站太原it培训机构
  • 胶州市 网站建设沙田镇网站仿做
  • 学生制作个人网站网站建设服务定制
  • 外贸都是在哪些网站做wordpress英文版本
  • 用织梦做的网站怎么上传虚拟ui首页界面设计
  • 免费设计logo的网站有哪些咋做抽奖网站
  • 个体营业执照网站建设优化加盟代理
  • 上海网站 建设景观设计师做交通分析常用网站
  • 如何修改网站后台时间南充做网站略奥网络