我可以使用powershell“绘制"/创建具有给定文本的图像吗? [英] Can I "draw"/create an image with a given text with powershell?
本文介绍了我可以使用powershell“绘制"/创建具有给定文本的图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想知道是否有可能在powershell中使用给定的文本创建小的,简单的jpg,png,gif:
I just wondered if it would be possible to create a small, simple jpg, png, gif with a given Text in powershell:
例如:一个小正方形,250px×61px,黄色背景,上面有黑色文字:测试"
e.g: a small square, 250px × 61px, yellow background and black text on it: "Test"
我可以使用"System.Drawing.Image"来做到这一点吗?
Can I do this with "System.Drawing.Image"?
谢谢
推荐答案
当然,如果您使用的是PowerShell 2.0,请尝试以下操作:
Sure, if you're on PowerShell 2.0 try this:
Add-Type -AssemblyName System.Drawing
$filename = "$home\foo.png"
$bmp = new-object System.Drawing.Bitmap 250,61
$font = new-object System.Drawing.Font Consolas,24
$brushBg = [System.Drawing.Brushes]::Yellow
$brushFg = [System.Drawing.Brushes]::Black
$graphics = [System.Drawing.Graphics]::FromImage($bmp)
$graphics.FillRectangle($brushBg,0,0,$bmp.Width,$bmp.Height)
$graphics.DrawString('Hello World',$font,$brushFg,10,10)
$graphics.Dispose()
$bmp.Save($filename)
Invoke-Item $filename
这篇关于我可以使用powershell“绘制"/创建具有给定文本的图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文