mirror of
https://github.com/dotnetcore/Util.git
synced 2026-10-19 13:41:24 +08:00
adaebbbb0e
2. 新增二维码组件标签 <util-qrcode> . 3. 新增水印组件标签 <util-water-mark> . 4. 新增哈希码组件标签 <util-hash-code> . 5. 新增回到顶部组件标签 <util-back-top> . 6. Json操作类 Util.Helpers.Json 的 JsonOptions 参数新增 IgnoreEmptyString 属性, 用于忽略空字符串. 7. 修复表单组件 SpaceItem 属性引起验证指令引用变量作用域错误导致的bug.
92 lines
2.7 KiB
C#
92 lines
2.7 KiB
C#
using System.Threading.Tasks;
|
|
using Util.Helpers;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Util.Images.Tests;
|
|
|
|
/// <summary>
|
|
/// 测试图片操作 - 写文本
|
|
/// </summary>
|
|
public class DrawTextTest {
|
|
/// <summary>
|
|
/// 测试输出
|
|
/// </summary>
|
|
private readonly ITestOutputHelper _testOutputHelper;
|
|
/// <summary>
|
|
/// 图片服务
|
|
/// </summary>
|
|
private readonly IImageManager _imageManager;
|
|
/// <summary>
|
|
/// 输出路径
|
|
/// </summary>
|
|
private const string Path = "./test/{0}.gif";
|
|
|
|
/// <summary>
|
|
/// 测试初始化
|
|
/// </summary>
|
|
public DrawTextTest( ITestOutputHelper testOutputHelper, IImageManager imageManager ) {
|
|
_testOutputHelper = testOutputHelper;
|
|
_imageManager = imageManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试 - 内置字体,指定坐标
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task Test_1() {
|
|
await _imageManager.CreateImage( 128, 128, "5d005d" )
|
|
.DefaultFontName( "Microsoft YaHei" )
|
|
.Font( 48 )
|
|
.Text( "U", "fff", 50, 38 )
|
|
.SaveAsync( string.Format( Path, "Test_1" ) );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试 - 加载字体,居中显示
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task Test_2() {
|
|
ImageManager.LoadFont( "a", Common.GetPhysicalPath( "~/Fonts/STZHONGS.TTF" ) );
|
|
await _imageManager.CreateImage( 128, 128, "5d005d" )
|
|
.Font( 48,"a" )
|
|
.TextCenter( "U", "fff" )
|
|
.SaveAsync( string.Format( Path, "Test_2" ) );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试获取流
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task TestToStreamAsync() {
|
|
var result = await _imageManager.CreateImage( 128, 128, "5d005d" )
|
|
.ImageType( ImageType.Gif )
|
|
.Font( 48 )
|
|
.TextCenter( "U", "fff" )
|
|
.ToStreamAsync();
|
|
await Util.Helpers.File.WriteAsync( string.Format( Path, "TestToStreamAsync" ),result );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试获取base64
|
|
/// </summary>
|
|
[Fact]
|
|
public void TestToBase64() {
|
|
var result = _imageManager.CreateImage( 128, 128, "5d005d" )
|
|
.ImageType( ImageType.Gif )
|
|
.Font( 48 )
|
|
.TextCenter( "U", "fff" )
|
|
.ToBase64();
|
|
_testOutputHelper.WriteLine( result );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试受支持的字体列表
|
|
/// </summary>
|
|
[Fact]
|
|
public void TestGetSupportedFonts() {
|
|
ImageManager.LoadFont( "a", Common.GetPhysicalPath( "~/Fonts/STZHONGS.TTF" ) );
|
|
var result = ImageManager.GetSupportedFonts();
|
|
_testOutputHelper.WriteLine( result.Join() );
|
|
}
|
|
} |