| | | | | | | | | | | | | | | | | $codes=@' | | using System; | | using System.IO; | | using System.Text; | | using System.Drawing; | | using System.Drawing.Imaging; | | public static class TextToImage{ | | public static void Save(string textFile,string imageFile){ | | System.Drawing.Font drawFont=new System.Drawing.Font("宋体", 14); | | System.Drawing.Bitmap image=new System.Drawing.Bitmap(1, 1); | | System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(image); | | String text=System.IO.File.ReadAllText(textFile, System.Text.Encoding.GetEncoding("GB2312")); | | System.Drawing.SizeF sf=g.MeasureString(text, drawFont, 1024); | | image=new System.Drawing.Bitmap(image, 1024, 1024); | | g=System.Drawing.Graphics.FromImage(image); | | g.Clear(System.Drawing.Color.White); | | g.TextRenderingHint=System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; | | g.DrawString(text, drawFont, System.Drawing.Brushes.Black, new System.Drawing.RectangleF(new System.Drawing.PointF(0, 0), sf)); | | image.Save(imageFile, System.Drawing.Imaging.ImageFormat.Jpeg); | | g.Dispose(); | | image.Dispose(); | | } | | } | | '@; | | Add-Type -TypeDefinition $codes -ReferencedAssemblies 'System.Drawing'; | | | | $self=get-item -liter $args[0]; | | $path=$self.Directory.FullName; | | $folders=@(dir -liter $path|?{$_ -is [System.IO.DirectoryInfo]}); | | for($i=0;$i -lt $folders.length;$i++){ | | $files=@(dir -liter $folders[$i].FullName|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}); | | for($j=0;$j -lt $files.length;$j++){ | | write-host ($files[$j].FullName.Substring($path.length)); | | $jpgfile=$files[$j].Directory.FullName+'\aa.jpg'; | | [TextToImage]::Save($files[$j].FullName,$jpgfile); | | } | | }COPY |
|