/// <summary> /// Creates a new instance of <see cref="HtmlToImage"/> class. /// </summary> /// <param name="options">Options.</param> /// <param name="loggerFactory">Logger factory</param> public HtmlToImage(HtmlToImageOptions options, ILoggerFactory loggerFactory) { this.logger = loggerFactory.CreateLogger <HtmlToImage>(); this.loggerFactory = loggerFactory; this.exectuionDirectory = options.ExectuionDirectory ?? new TempExectuionDirectory(); this.workdir = Path.Combine(exectuionDirectory.Directory, Path.GetRandomFileName() + ".dir"); this.depencencyLogger = options.DependencyLogger; this.executionTimeout = options.ExecutionTimeout; if (!Directory.Exists(workdir)) { Directory.CreateDirectory(workdir); } if (Environment.Is64BitProcess) { resourceApplicationName = "SolidCompany.Wrappers.WkHtmlToImage.Resources.wkhtmltoimage-x64.zip"; } else { resourceApplicationName = "SolidCompany.Wrappers.WkHtmlToImage.Resources.wkhtmltoimage-x86.zip"; } this.wkhtmlToImpageExePath = Path.Combine(exectuionDirectory.Directory, ApplicationName); this.initializeTask = InitializeAsync(); }
public async Task Can_generate_image() { var options = new HtmlToImageOptions { ExectuionDirectory = new CustomDirectory(TestContext.CurrentContext.WorkDirectory) }; using var htmlToImage = new HtmlToImage(options, NullLoggerFactory.Instance); var stream = await htmlToImage.CreateImageAsync("<html><body style=\"background-color: red\"></body></html>", 100, ImageFormat.Png); Assert.That(stream.Length, Is.GreaterThan(0)); }