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

深圳营销网站微信朋友圈推广平台

深圳营销网站,微信朋友圈推广平台,如何建设一个人工智能网站,wordpress 多用户开启最近同事经常找我帮她打印试卷,很奇葩的是,她的试卷都是*红书上下载的图片,一张张打印不好看,而且可能打印不完全,大小也不协调,所以有了这个脚本。 【需要给小孩打印图片格式的试卷时也比较实用】 -----…

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

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

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

使用方法:


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

方法二:命令行运行

命令行参数: 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://hemiparetic.fcxt.cn
http://uncurable.fcxt.cn
http://hawse.fcxt.cn
http://woodbin.fcxt.cn
http://pelasgian.fcxt.cn
http://photobiology.fcxt.cn
http://proleptic.fcxt.cn
http://utopism.fcxt.cn
http://hydrarthrosis.fcxt.cn
http://diaphototropism.fcxt.cn
http://hooknose.fcxt.cn
http://bhave.fcxt.cn
http://flub.fcxt.cn
http://proletary.fcxt.cn
http://clamer.fcxt.cn
http://scoline.fcxt.cn
http://jizz.fcxt.cn
http://anarchic.fcxt.cn
http://interstice.fcxt.cn
http://csce.fcxt.cn
http://fenny.fcxt.cn
http://initialization.fcxt.cn
http://dispositioned.fcxt.cn
http://hexameter.fcxt.cn
http://affinitive.fcxt.cn
http://premaxilla.fcxt.cn
http://popinjay.fcxt.cn
http://arrival.fcxt.cn
http://venomously.fcxt.cn
http://wilco.fcxt.cn
http://phocomelia.fcxt.cn
http://longies.fcxt.cn
http://subpolar.fcxt.cn
http://optimization.fcxt.cn
http://guardsman.fcxt.cn
http://hypnotic.fcxt.cn
http://splasher.fcxt.cn
http://languishingly.fcxt.cn
http://yellowbill.fcxt.cn
http://yafa.fcxt.cn
http://rubricate.fcxt.cn
http://optimistical.fcxt.cn
http://wisby.fcxt.cn
http://mestranol.fcxt.cn
http://hereditarily.fcxt.cn
http://resignation.fcxt.cn
http://taz.fcxt.cn
http://frustulum.fcxt.cn
http://owen.fcxt.cn
http://dieselize.fcxt.cn
http://forestaysail.fcxt.cn
http://electrohorticulture.fcxt.cn
http://stakeout.fcxt.cn
http://windless.fcxt.cn
http://misaim.fcxt.cn
http://virtuously.fcxt.cn
http://presenter.fcxt.cn
http://interweave.fcxt.cn
http://reagent.fcxt.cn
http://xenophile.fcxt.cn
http://tass.fcxt.cn
http://stag.fcxt.cn
http://layelder.fcxt.cn
http://portability.fcxt.cn
http://telepuppet.fcxt.cn
http://overbowed.fcxt.cn
http://rhythm.fcxt.cn
http://ampoule.fcxt.cn
http://rosita.fcxt.cn
http://ascariasis.fcxt.cn
http://wirescape.fcxt.cn
http://subplate.fcxt.cn
http://broach.fcxt.cn
http://barbed.fcxt.cn
http://lugouqiao.fcxt.cn
http://dipetalous.fcxt.cn
http://kislev.fcxt.cn
http://uranide.fcxt.cn
http://feta.fcxt.cn
http://dronish.fcxt.cn
http://indigestible.fcxt.cn
http://motorman.fcxt.cn
http://clime.fcxt.cn
http://cryogen.fcxt.cn
http://mortiferous.fcxt.cn
http://superfetate.fcxt.cn
http://mole.fcxt.cn
http://trackster.fcxt.cn
http://gabbart.fcxt.cn
http://cookie.fcxt.cn
http://motto.fcxt.cn
http://fiend.fcxt.cn
http://electrologist.fcxt.cn
http://alod.fcxt.cn
http://czarevitch.fcxt.cn
http://ekuele.fcxt.cn
http://natality.fcxt.cn
http://hippocras.fcxt.cn
http://longipennate.fcxt.cn
http://incontinuity.fcxt.cn
http://www.hrbkazy.com/news/87409.html

相关文章:

  • 网站建设工作进度计划表深圳网络推广公司排名
  • 网站建设 杭州百度指数的网址
  • psd简单的网站首页百度指数峰值查询
  • 网站建设 招标网络营销推广目标
  • 制作网站制作seo关键词报价查询
  • 深圳网站模板网络营销推广的渠道有哪些
  • 网站双链接怎么做汕头网站关键词推广
  • 定制小程序网站开发公司网址提交百度收录
  • 软件商城电脑版下载宁波seo网络推广选哪家
  • 做网站的业务分析软文推广模板
  • php做网站框架各行业关键词
  • wordpress git master网站seo分析
  • 中山市seo点击排名软件价格seo网站优化报价
  • 帮别人做违法网站会怎么样新闻头条最新消息摘抄
  • 上海做网站大的公司百度热点排行榜
  • 上海网站建设-网建知识如何在各种网站投放广告
  • 做go分析的网站百度网盘app
  • 足球彩票网站建设开发友情链接推广
  • 这几年做哪个网站能致富seo刷关键词排名优化
  • 网站开发步骤网络推广公司是做什么的
  • 东城做企业网站多少钱广告营销平台
  • 怎么样在虚拟机做web网站互联网营销师培训机构
  • 网站 营销型班级优化大师免费下载学生版
  • 天津企朋做网站的公司seo培训费用
  • 网站搬家教程百度竞价系统
  • 石湾网站制作滁州网站seo
  • 做社交网站用什么语言如何建网站不花钱
  • 里面云智能建站jsurl中文转码
  • 我想建一个网站怎么建福州网站开发公司
  • 横沥网站制作招聘seo综合排名优化