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

怎么做自己的个人网站做个网站需要多少钱

怎么做自己的个人网站,做个网站需要多少钱,数码产品网站建设策划书,独立网站建设空间哪里买最近同事经常找我帮她打印试卷,很奇葩的是,她的试卷都是*红书上下载的图片,一张张打印不好看,而且可能打印不完全,大小也不协调,所以有了这个脚本。 【需要给小孩打印图片格式的试卷时也比较实用】 -----…

最近同事经常找我帮她打印试卷,很奇葩的是,她的试卷都是*红书上下载的图片,一张张打印不好看,而且可能打印不完全,大小也不协调,所以有了这个脚本。

【需要给小孩打印图片格式的试卷时也比较实用】

---------------------------------------------------------------------------------------------------------------------------------

使用方法:


方法一:直接将脚本放到图片文件夹内,并运行脚本

方法二:命令行运行

命令行参数: 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", shell=True)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, pagesize=letter)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_file=None):"""遍历给定路径,将路径下的图片添加进pdf,并将pdf保存在指定路径下"""images = get_images(img_folder)if images:if not pdf_file:pdf_name = os.path.basename(img_folder) + ".pdf"pdf_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_length=60):"""进度条"""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", shell=True)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.ds6.com.cn/news/43409.html

相关文章:

  • 移动端网站制作案例怎么联系百度人工客服
  • 佛山网站推广注册推广赚钱一个10元
  • 石家庄造价工程信息网seo推广教程
  • 电商网站 费用设计公司排名
  • 网站上的缩略图怎么做清晰刚刚发生 北京严重发生
  • 做网站卖掉网页制作软件免费版
  • 上海市网站seo公司电视剧排行榜百度搜索风云榜
  • 怎样做士产品销售网站营销模式有几种
  • jquery代码做的网站做百度推广需要什么条件
  • 成品网站 智能建站郑州网站优化哪家好
  • 怎么做汽车网站推广方案合肥seo按天收费
  • 网站网页制作电话企业培训
  • 怎样在中国建设银行网站开通短信提醒软文写作的三个要素
  • 石家庄最好的网站建设公司排名php开源建站系统
  • 凡科网商城泰安优化关键词排名哪家合适
  • seo关键词优化推广西安优化外
  • 做视频网站需要哪些技术指标推销产品怎么推广
  • 丹阳网站设计郑州百度公司地址
  • 网站点击量在哪里看网络营销培训课程
  • 广西建设厅网站招 标 信 息优化设计官方电子版
  • 删格化网站设计视频推广渠道有哪些
  • 网站代码跑偏了怎么做免费友情链接交换平台
  • 南京企业网站seo南宁网站推广排名
  • wordpress开玩笑_呵?百度关键词优化工具
  • 做网站怎么拿框架的原代码平台app开发制作
  • 网站搭建与网站建设网站新站整站排名
  • qq是哪个国家公司开发的软件seo在线网站推广
  • 域名空间都有了怎么做网站百度推广账号登陆入口
  • 做网站公司需要什么谷歌seo快速排名软件首页
  • 自己做行程的网站指数基金定投技巧