[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

批量把txt文本里的内容做成图片

本帖最后由 xiaohutok1 于 2021-8-23 23:34 编辑

文本里行数都是30行左右,内容没有很多。 我要的效果和截个图差不多。 做成正方形的图片。
每个子文件夹里都有一个txt文本,弄成图片后放到各自的文件夹里就行,文件名就aa.jpg
自己一个一个去弄成图片好麻烦

有偿 150

  1. <# :
  2. cls&echo off
  3. rem txt及bat的编码存为ANSI/GB2312
  4. cd /d "%~dp0"
  5. powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312')))) -Args '%~f0'"
  6. pause
  7. exit
  8. #>
  9. $codes=@'
  10. using System;
  11. using System.IO;
  12. using System.Text;
  13. using System.Drawing;
  14. using System.Drawing.Imaging;
  15. public static class TextToImage{
  16.     public static void Save(string textFile,string imageFile){
  17.         System.Drawing.Font drawFont=new System.Drawing.Font("宋体", 14);
  18.         System.Drawing.Bitmap image=new System.Drawing.Bitmap(1, 1);
  19.         System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(image);
  20.         String text=System.IO.File.ReadAllText(textFile, System.Text.Encoding.GetEncoding("GB2312"));
  21.         System.Drawing.SizeF sf=g.MeasureString(text, drawFont, 1024);
  22.         image=new System.Drawing.Bitmap(image, 1024, 1024);
  23.         g=System.Drawing.Graphics.FromImage(image);
  24.         g.Clear(System.Drawing.Color.White);
  25.         g.TextRenderingHint=System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
  26.         g.DrawString(text, drawFont, System.Drawing.Brushes.Black, new System.Drawing.RectangleF(new System.Drawing.PointF(0, 0), sf));
  27.         image.Save(imageFile, System.Drawing.Imaging.ImageFormat.Jpeg);
  28.         g.Dispose();
  29.         image.Dispose();
  30.     }
  31. }
  32. '@;
  33. Add-Type -TypeDefinition $codes -ReferencedAssemblies 'System.Drawing';
  34. $self=get-item -liter $args[0];
  35. $path=$self.Directory.FullName;
  36. $folders=@(dir -liter $path|?{$_ -is [System.IO.DirectoryInfo]});
  37. for($i=0;$i -lt $folders.length;$i++){
  38.     $files=@(dir -liter $folders[$i].FullName|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
  39.     for($j=0;$j -lt $files.length;$j++){
  40.         write-host ($files[$j].FullName.Substring($path.length));
  41.         $jpgfile=$files[$j].Directory.FullName+'\aa.jpg';
  42.         [TextToImage]::Save($files[$j].FullName,$jpgfile);
  43.     }
  44. }
复制代码
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 2# zaqmlp


    查收

TOP

回复 2# zaqmlp


    哥 ,能不能帮我稍微改下。  其他都一样,添加一个指定文件名的txt处理,其他的txt不处理。 谢谢

TOP

返回列表