protected override void ProcessRecord() { if (parPath.StartsWith(@".\")) { parPath = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, parPath.Substring(2)); } Image rawImage = ((new Uri(parPath).IsFile)) ? rawImage = ImageEncoding.ReadImage(System.IO.Path.GetFullPath(parPath)) : ImageEncoding.DownloadImage(parPath); WriteObject(ImageEncoding.ImageToBase64String(rawImage)); }
protected override void ProcessRecord() { if (parPath.StartsWith(@".\")) { parPath = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, parPath.Substring(2)); } parPath = System.IO.Path.GetFullPath(parPath); string htmlData = File.ReadAllText(parPath); htmlData = Regex.Replace(htmlData, "(?=<img)(.*?)src=[\"|'](.*?)[\"|']", delegate(Match match) { Image rawImage = ((new Uri(match.Groups[2].Value).IsFile)) ? rawImage = ImageEncoding.ReadImage(System.IO.Path.GetFullPath(match.Groups[2].Value)) : ImageEncoding.DownloadImage(match.Groups[2].Value); string encodedImage = ImageEncoding.ImageToBase64String(rawImage); return(string.Format("{0}src=\"data:image/image;base64,{1}\"", match.Groups[1].Value, encodedImage)); }); string newName = string.Format("{1}\\{0}.htapp", System.IO.Path.GetFileNameWithoutExtension(parPath), System.IO.Path.GetDirectoryName(parPath)); string header = Templates.StandardBlock; header = header.Replace("$WIDTH$", parWidth.ToString()); header = header.Replace("$HEIGHT$", parHeight.ToString()); header = header.Replace("$TITLE$", parTitle); htmlData = header + htmlData; File.WriteAllText(newName, htmlData); }