public void SaveImageTest() { var path = TestImageLogo; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.SaveImage(Path.Combine(SaveDirectory, "test.jpg")); wand.SaveImage(Path.Combine(SaveDirectory, "test.png")); wand.SaveImage(Path.Combine(SaveDirectory, "test.webp")); } }
public void ResizeImageTest() { var path = TestImageLogo; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.CurrentImage.ResizeImage(400, 150); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.jpg")); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.png")); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.webp")); } }
public void ResizeImageTestDir() { var path = @"D:\Video\TV\Carnivàle\Season 2\Carnivàle - 2x09 - Lincoln Highway DVD.jpg"; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.CurrentImage.ResizeImage(400, 150); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.jpg")); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.png")); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.webp")); } }
public async Task EnhanceImageAsync(IHasImages item, string inputPath, string outputPath, ImageType imageType, int imageIndex) { using (MagickWand img = await this.EnhanceImageAsyncInternal(item, new MagickWand(inputPath), imageType, imageIndex)) { img.SaveImage(outputPath); } }
public void EncodeImage(string inputPath, string outputPath, int width, int height, int quality, ImageProcessingOptions options) { if (string.IsNullOrWhiteSpace(options.BackgroundColor) || !HasTransparency(inputPath)) { using (var originalImage = new MagickWand(inputPath)) { originalImage.CurrentImage.ResizeImage(width, height); DrawIndicator(originalImage, width, height, options); originalImage.CurrentImage.CompressionQuality = quality; originalImage.SaveImage(outputPath); } } else { using (var wand = new MagickWand(width, height, options.BackgroundColor)) { using (var originalImage = new MagickWand(inputPath)) { originalImage.CurrentImage.ResizeImage(width, height); wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0); DrawIndicator(wand, width, height, options); wand.CurrentImage.CompressionQuality = quality; wand.SaveImage(outputPath); } } } SaveDelay(); }
public void DrawingWandAnnotationTest() { //using (var wand = new MagickWand(TestImageBackdrop)) using (var wand = new MagickWand(400, 100, "#ffffff")) { //wand.NewImage(400, 200, new PixelWand("white")); //wand.OpenImage(TestImageBackdrop); using (var draw = new DrawingWand()) { using (PixelWand pixel = new PixelWand("black")) { draw.FillColor = pixel; draw.Font = "Arial"; draw.FontSize = 20; draw.FontStyle = FontStyleType.NormalStyle; draw.TextAlignment = TextAlignType.LeftAlign; draw.FontWeight = FontWeightType.BoldStyle; draw.TextAntialias = true; draw.DrawAnnotation(0, 20, "Media Browser"); draw.BorderColor = new PixelWand("red"); //draw.Font = "Times-New-Roman"; //pixel.Color = "Red"; //pixel.Opacity = 0.8; //draw.FillColor = pixel; //draw.DrawAnnotation(60, 120, "Tavares"); Debug.WriteLine(draw); wand.CurrentImage.DrawImage(draw); } } //Debug.WriteLine(wand.GetNumberImages()); //wand.Image.TrimImage(10); wand.SaveImage(Path.Combine(SaveDirectory, "logo_extent.jpg")); } }
public void MediaBrowserWandRoundCornersTest() { var cofactor = 15; using (var wand = new MagickWand(TestImageBackdrop).RoundCorners(cofactor)) wand.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.png")); }
public void MediaBrowserWandCropWhitespaceTests() { using (var wand = new MagickWand(TestImageLogo)) { wand.CurrentImage.TrimImage(10); wand.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.png")); } }
public void CoverArtWandRotateTests() { using (var wand = new MagickWand(this.TestImageFolder1)) { wand.CurrentImage.RotateImage(new PixelWand("transparent", 1), 30); //wand.CurrentImage.TrimImage(10); wand.SaveImage(Path.Combine(SaveDirectory, "logo_extent.png")); } }
public void SaveImageWithQualityTest() { var path = TestImageFolder3; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.CurrentImage.CompressionQuality = 90; wand.SaveImage(Path.Combine(SaveDirectory, "test.jpg")); wand.CurrentImage.CompressionQuality = 90; wand.SaveImage(Path.Combine(SaveDirectory, "test.png")); wand.CurrentImage.CompressionQuality = 90; wand.SaveImage(Path.Combine(SaveDirectory, "test.webp")); } }
public void NewImageTest2() { using (var wand = new MagickWand(100, 100, "#ffffff")) { //wand.NewImage(100, 100, "#ffffff"); wand.SaveImage(Path.Combine(SaveDirectory, "TestSetBackgroundColor.png")); } }
public void CoverArtWandRotateTests() { using (var wand = new MagickWand(this.TestImageFolder1)) { wand.CurrentImage.RotateImage(new PixelWand("transparent", 1), 30); //wand.CurrentImage.TrimImage(10); wand.SaveImage(Path.Combine(SaveDirectory, "logo_extent.png")); } }
public void CropWhiteSpace(string inputPath, string outputPath) { CheckDisposed(); using (var wand = new MagickWand(inputPath)) { wand.CurrentImage.TrimImage(10); wand.SaveImage(outputPath); } }
public void OpenImageTestWebp() { var path = TestImageFolder5; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.SaveImage(Path.Combine(SaveDirectory, "test.png")); } }
internal static Stream GetStream(MagickWand image, IApplicationPaths appPaths) { var tempFile = Path.Combine(appPaths.TempDirectory, Guid.NewGuid().ToString("N") + ".png"); Directory.CreateDirectory(Path.GetDirectoryName(tempFile)); image.CurrentImage.CompressionQuality = 100; image.SaveImage(tempFile); return(File.OpenRead(tempFile)); }
public void EncodeImage(string inputPath, string outputPath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) { // Even if the caller specified 100, don't use it because it takes forever quality = Math.Min(quality, 99); if (string.IsNullOrWhiteSpace(options.BackgroundColor) || !HasTransparency(inputPath)) { using (var originalImage = new MagickWand(inputPath)) { ScaleImage(originalImage, width, height); if (autoOrient) { AutoOrientImage(originalImage); } AddForegroundLayer(originalImage, options); DrawIndicator(originalImage, width, height, options); originalImage.CurrentImage.CompressionQuality = quality; originalImage.CurrentImage.StripImage(); originalImage.SaveImage(outputPath); } } else { using (var wand = new MagickWand(width, height, options.BackgroundColor)) { using (var originalImage = new MagickWand(inputPath)) { ScaleImage(originalImage, width, height); if (autoOrient) { AutoOrientImage(originalImage); } wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0); AddForegroundLayer(wand, options); DrawIndicator(wand, width, height, options); wand.CurrentImage.CompressionQuality = quality; wand.CurrentImage.StripImage(); wand.SaveImage(outputPath); } } } SaveDelay(); }
public void MediaBrowserWandOverlayTests() { using (var wand = new MagickWand(TestImageBackdrop)) { using (MagickWand wandComposit = new MagickWand(TestImageLogo)) { //draw.FillOpacity = 0.5; wand.CurrentImage.OverlayImage(CompositeOperator.AtopCompositeOp, 560, 660, wandComposit.CurrentImage.Width, wandComposit.CurrentImage.Height, wandComposit); } wand.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.jpg")); } }
public void CoverArtWandShadowTests() { using (var wand = new MagickWand(TestImageFolder1)) { using (MagickWand nailclone = wand.CloneMagickWand()) using (var blackPixelWand = new PixelWand(ColorName.Black)) { nailclone.CurrentImage.BackgroundColor = blackPixelWand; nailclone.CurrentImage.ShadowImage(80, 5, 5, 5); nailclone.CurrentImage.CompositeImage(wand, CompositeOperator.CopyCompositeOp, 0, 0); nailclone.SaveImage(Path.Combine(SaveDirectory, "logo_extent.png")); } } }
public void MediaBrowserClipMaskTest() { var dest = new MagickWand(100, 100); var mask = new MagickWand(); var src = new MagickWand(100, 100); dest.OpenImage(this.TestImageFolder1); mask.OpenImage(this.TestImageFolder2); mask.CurrentImage.NegateImage(false); mask.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdropMask.png")); dest.CurrentImage.SetImageClipMask(mask); src.OpenImage(this.TestImageBackdrop); dest.CurrentImage.CompositeImage(src, CompositeOperator.OverCompositeOp, 0, 0); dest.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.png")); }
public void MediaBrowserClipMaskTest() { var dest = new MagickWand(100, 100); var mask = new MagickWand(); var src = new MagickWand(100, 100); dest.OpenImage(this.TestImageFolder1); mask.OpenImage(this.TestImageFolder2); mask.CurrentImage.NegateImage(false); mask.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdropMask.png")); dest.CurrentImage.SetImageClipMask(mask); src.OpenImage(this.TestImageBackdrop); dest.CurrentImage.CompositeImage(src, CompositeOperator.OverCompositeOp, 0, 0); dest.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.png")); }
private void TestWebp() { try { var tmpPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".webp"); Directory.CreateDirectory(Path.GetDirectoryName(tmpPath)); using (var wand = new MagickWand(1, 1, new PixelWand("none", 1))) { wand.SaveImage(tmpPath); } } catch (Exception ex) { _logger.ErrorException("Error loading webp: ", ex); _webpAvailable = false; } }
public void MediaBrowserWandTextTests() { using (var wand = new MagickWand(TestImageBackdrop)) using (var yellowPixelWand = new PixelWand("yellow")) using (var whitePixelWand = new PixelWand("white")) using (var blackPixelWand = new PixelWand("black", 0.5)) { wand.CurrentImage.DrawRoundRectangle(10, 10, wand.CurrentImage.Width - 10, 70, 5, 5, yellowPixelWand, blackPixelWand); wand.CurrentImage.DrawCircle(400, 300, 500, 400, yellowPixelWand, blackPixelWand); wand.CurrentImage.DrawCircle(400, 400, 60, yellowPixelWand, blackPixelWand); wand.CurrentImage.DrawRectangle(0, wand.CurrentImage.Height - 70, wand.CurrentImage.Width - 1, wand.CurrentImage.Height, yellowPixelWand, blackPixelWand); wand.CurrentImage.DrawText("Media Browser", 10, wand.CurrentImage.Height - 10, "Arial", 60, whitePixelWand, FontWeightType.BoldStyle); wand.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.jpg")); } }
private void TestWebp() { try { var tmpPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".webp"); _fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath)); using (var wand = new MagickWand(1, 1, new PixelWand("none", 1))) { wand.SaveImage(tmpPath); } } catch { //_logger.ErrorException("Error loading webp: ", ex); _webpAvailable = false; } }
/// <summary> /// Crops whitespace from an image, caches the result, and returns the cached path /// </summary> /// <param name="originalImagePath">The original image path.</param> /// <param name="dateModified">The date modified.</param> /// <returns>System.String.</returns> private async Task <Tuple <string, DateTime> > GetWhitespaceCroppedImage(string originalImagePath, DateTime dateModified) { var name = originalImagePath; name += "datemodified=" + dateModified.Ticks; var croppedImagePath = GetCachePath(CroppedWhitespaceImageCachePath, name, Path.GetExtension(originalImagePath)); var semaphore = GetLock(croppedImagePath); await semaphore.WaitAsync().ConfigureAwait(false); // Check again in case of contention if (File.Exists(croppedImagePath)) { semaphore.Release(); return(new Tuple <string, DateTime>(croppedImagePath, _fileSystem.GetLastWriteTimeUtc(croppedImagePath))); } try { Directory.CreateDirectory(Path.GetDirectoryName(croppedImagePath)); using (var wand = new MagickWand(originalImagePath)) { wand.CurrentImage.TrimImage(10); wand.SaveImage(croppedImagePath); } } catch (Exception ex) { // We have to have a catch-all here because some of the .net image methods throw a plain old Exception _logger.ErrorException("Error cropping image {0}", ex, originalImagePath); return(new Tuple <string, DateTime>(originalImagePath, dateModified)); } finally { semaphore.Release(); } return(new Tuple <string, DateTime>(croppedImagePath, _fileSystem.GetLastWriteTimeUtc(croppedImagePath))); }
public void ExtendcanvasaroundimageTest() { var path = TestImageThumb; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.OpenImage(path); var w = wand.CurrentImage.Width; var h = wand.CurrentImage.Height; using (PixelWand newPixelWand = new PixelWand("blue")) { wand.CurrentImage.BackgroundColor = newPixelWand; } wand.CurrentImage.ExtentImage(1024, 768, -(1024 - w) / 2, -(768 - h) / 2); wand.SaveImage(Path.Combine(SaveDirectory, "logo_extent.jpg")); } }
public void ExtendcanvasaroundimageTest() { var path = TestImageThumb; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.OpenImage(path); var w = wand.CurrentImage.Width; var h = wand.CurrentImage.Height; using (PixelWand newPixelWand = new PixelWand("blue")) { wand.CurrentImage.BackgroundColor = newPixelWand; } wand.CurrentImage.ExtentImage(1024, 768, -(1024 - w) / 2, -(768 - h) / 2); wand.SaveImage(Path.Combine(SaveDirectory, "logo_extent.jpg")); } }
public void DrawingWandRectangleTest() { using (var wand = new MagickWand(TestImageBackdrop)) { //wand.NewImage(400, 200, new PixelWand("white")); //wand.OpenImage(TestImageBackdrop); using (var draw = new DrawingWand()) { using (PixelWand pixel = new PixelWand()) { pixel.Color = "red"; draw.StrokeColor = pixel; pixel.Color = "black"; pixel.Opacity = 0.5; draw.FillColor = pixel; draw.DrawRectangle(0, 0, wand.CurrentImage.Width - 1, 120); pixel.Color = "transparent"; draw.StrokeColor = pixel; pixel.Color = "white"; draw.FillColor = pixel; draw.Font = "Verdana"; draw.FontSize = 120; draw.FontStyle = FontStyleType.NormalStyle; draw.TextAlignment = TextAlignType.LeftAlign; draw.FontWeight = FontWeightType.BoldStyle; draw.TextAntialias = true; draw.DrawAnnotation(10, 100, "Media Browser"); draw.FillColor = pixel; wand.CurrentImage.DrawImage(draw); } } //Debug.WriteLine(wand.GetNumberImages()); //wand.Image.TrimImage(10); wand.SaveImage(Path.Combine(SaveDirectory, "logo_extent.jpg")); } }
public void DrawingWandAnnotationTest() { //using (var wand = new MagickWand(TestImageBackdrop)) using (var wand = new MagickWand(400, 100, "#ffffff")) { //wand.NewImage(400, 200, new PixelWand("white")); //wand.OpenImage(TestImageBackdrop); using (var draw = new DrawingWand()) { using (PixelWand pixel = new PixelWand("black")) { draw.FillColor = pixel; draw.Font = "Arial"; draw.FontSize = 20; draw.FontStyle = FontStyleType.NormalStyle; draw.TextAlignment = TextAlignType.LeftAlign; draw.FontWeight = FontWeightType.BoldStyle; draw.TextAntialias = true; draw.DrawAnnotation(0, 20, "Media Browser"); draw.BorderColor = new PixelWand("red"); //draw.Font = "Times-New-Roman"; //pixel.Color = "Red"; //pixel.Opacity = 0.8; //draw.FillColor = pixel; //draw.DrawAnnotation(60, 120, "Tavares"); Debug.WriteLine(draw); wand.CurrentImage.DrawImage(draw); } } //Debug.WriteLine(wand.GetNumberImages()); //wand.Image.TrimImage(10); wand.SaveImage(Path.Combine(SaveDirectory, "logo_extent.jpg")); } }
public void EncodeImage(string inputPath, string outputPath, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) { // Even if the caller specified 100, don't use it because it takes forever quality = Math.Min(quality, 99); if (string.IsNullOrWhiteSpace(options.BackgroundColor) || !HasTransparency(inputPath)) { using (var originalImage = new MagickWand(inputPath)) { ScaleImage(originalImage, width, height); DrawIndicator(originalImage, width, height, options); originalImage.CurrentImage.CompressionQuality = quality; originalImage.CurrentImage.StripImage(); originalImage.SaveImage(outputPath); } } else { using (var wand = new MagickWand(width, height, options.BackgroundColor)) { using (var originalImage = new MagickWand(inputPath)) { ScaleImage(originalImage, width, height); wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0); DrawIndicator(wand, width, height, options); wand.CurrentImage.CompressionQuality = quality; wand.CurrentImage.StripImage(); wand.SaveImage(outputPath); } } } SaveDelay(); }
public void EncodeImage(string inputPath, string outputPath, int width, int height, int quality, ImageProcessingOptions options) { if (string.IsNullOrWhiteSpace(options.BackgroundColor) || !HasTransparency(inputPath)) { using (var originalImage = new MagickWand(inputPath)) { originalImage.CurrentImage.ResizeImage(width, height); DrawIndicator(originalImage, width, height, options); originalImage.CurrentImage.CompressionQuality = quality; originalImage.SaveImage(outputPath); } } else { using (var wand = new MagickWand(width, height, options.BackgroundColor)) { using (var originalImage = new MagickWand(inputPath)) { originalImage.CurrentImage.ResizeImage(width, height); wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0); DrawIndicator(wand, width, height, options); wand.CurrentImage.CompressionQuality = quality; wand.SaveImage(outputPath); } } } SaveDelay(); }
public void CropWhiteSpace(string inputPath, string outputPath) { CheckDisposed(); using (var wand = new MagickWand(inputPath)) { wand.CurrentImage.TrimImage(10); wand.SaveImage(outputPath); } SaveDelay(); }
public void OpenImageTestWebp() { var path = TestImageFolder5; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.SaveImage(Path.Combine(SaveDirectory, "test.png")); } }
public void NewImageTest2() { using (var wand = new MagickWand(100, 100, "#ffffff")) { //wand.NewImage(100, 100, "#ffffff"); wand.SaveImage(Path.Combine(SaveDirectory, "TestSetBackgroundColor.png")); } }
public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation?orientation, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) { // Even if the caller specified 100, don't use it because it takes forever quality = Math.Min(quality, 99); if (string.IsNullOrWhiteSpace(options.BackgroundColor) || !HasTransparency(inputPath)) { using (var originalImage = new MagickWand(inputPath)) { if (options.CropWhiteSpace) { originalImage.CurrentImage.TrimImage(10); } var originalImageSize = new ImageSize(originalImage.CurrentImage.Width, originalImage.CurrentImage.Height); if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize)) { // Just spit out the original file if all the options are default return(inputPath); } var newImageSize = ImageHelper.GetNewImageSize(options, originalImageSize); var width = Convert.ToInt32(Math.Round(newImageSize.Width)); var height = Convert.ToInt32(Math.Round(newImageSize.Height)); ScaleImage(originalImage, width, height, options.Blur ?? 0); if (autoOrient) { AutoOrientImage(originalImage); } AddForegroundLayer(originalImage, options); DrawIndicator(originalImage, width, height, options); originalImage.CurrentImage.CompressionQuality = quality; originalImage.CurrentImage.StripImage(); originalImage.SaveImage(outputPath); } } else { using (var originalImage = new MagickWand(inputPath)) { var originalImageSize = new ImageSize(originalImage.CurrentImage.Width, originalImage.CurrentImage.Height); var newImageSize = ImageHelper.GetNewImageSize(options, originalImageSize); var width = Convert.ToInt32(Math.Round(newImageSize.Width)); var height = Convert.ToInt32(Math.Round(newImageSize.Height)); using (var wand = new MagickWand(width, height, options.BackgroundColor)) { ScaleImage(originalImage, width, height, options.Blur ?? 0); if (autoOrient) { AutoOrientImage(originalImage); } wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0); AddForegroundLayer(wand, options); DrawIndicator(wand, width, height, options); wand.CurrentImage.CompressionQuality = quality; wand.CurrentImage.StripImage(); wand.SaveImage(outputPath); } } } return(outputPath); }
public void MediaBrowserWandRoundCornersTest() { var cofactor = 15; using (var wand = new MagickWand(TestImageBackdrop).RoundCorners(cofactor)) wand.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.png")); }
public void MediaBrowserWandCropWhitespaceTests() { using (var wand = new MagickWand(TestImageLogo)) { wand.CurrentImage.TrimImage(10); wand.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.png")); } }
public void SaveImageTest() { var path = TestImageLogo; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.SaveImage(Path.Combine(SaveDirectory, "test.jpg")); wand.SaveImage(Path.Combine(SaveDirectory, "test.png")); wand.SaveImage(Path.Combine(SaveDirectory, "test.webp")); } }
public void MediaBrowserWandTextTests() { using (var wand = new MagickWand(TestImageBackdrop)) using (var yellowPixelWand = new PixelWand("yellow")) using (var whitePixelWand = new PixelWand("white")) using (var blackPixelWand = new PixelWand("black", 0.5)) { wand.CurrentImage.DrawRoundRectangle(10, 10, wand.CurrentImage.Width - 10, 70, 5, 5, yellowPixelWand, blackPixelWand); wand.CurrentImage.DrawCircle(400, 300, 500, 400, yellowPixelWand, blackPixelWand); wand.CurrentImage.DrawCircle(400, 400, 60, yellowPixelWand, blackPixelWand); wand.CurrentImage.DrawRectangle(0, wand.CurrentImage.Height - 70, wand.CurrentImage.Width - 1, wand.CurrentImage.Height, yellowPixelWand, blackPixelWand); wand.CurrentImage.DrawText("Media Browser", 10, wand.CurrentImage.Height - 10, "Arial", 60, whitePixelWand, FontWeightType.BoldStyle); wand.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.jpg")); } }
public void SaveImageWithQualityTest() { var path = TestImageFolder3; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.CurrentImage.CompressionQuality = 90; wand.SaveImage(Path.Combine(SaveDirectory, "test.jpg")); wand.CurrentImage.CompressionQuality = 90; wand.SaveImage(Path.Combine(SaveDirectory, "test.png")); wand.CurrentImage.CompressionQuality = 90; wand.SaveImage(Path.Combine(SaveDirectory, "test.webp")); } }
public async Task <string> ProcessImage(ImageProcessingOptions options) { if (options == null) { throw new ArgumentNullException("options"); } var originalImagePath = options.Image.Path; if (options.HasDefaultOptions(originalImagePath) && options.Enhancers.Count == 0 && !options.CropWhiteSpace) { // Just spit out the original file if all the options are default return(originalImagePath); } var dateModified = options.Image.DateModified; if (options.CropWhiteSpace) { var tuple = await GetWhitespaceCroppedImage(originalImagePath, dateModified).ConfigureAwait(false); originalImagePath = tuple.Item1; dateModified = tuple.Item2; } if (options.Enhancers.Count > 0) { var tuple = await GetEnhancedImage(options.Image, options.Item, options.ImageIndex, options.Enhancers).ConfigureAwait(false); originalImagePath = tuple.Item1; dateModified = tuple.Item2; } var originalImageSize = GetImageSize(originalImagePath, dateModified); // Determine the output size based on incoming parameters var newSize = DrawingUtils.Resize(originalImageSize, options.Width, options.Height, options.MaxWidth, options.MaxHeight); if (options.HasDefaultOptionsWithoutSize(originalImagePath) && newSize.Equals(originalImageSize) && options.Enhancers.Count == 0) { // Just spit out the original file if the new size equals the old return(originalImagePath); } var quality = options.Quality ?? 90; var outputFormat = GetOutputFormat(options.OutputFormat); var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor); var semaphore = GetLock(cacheFilePath); await semaphore.WaitAsync().ConfigureAwait(false); // Check again in case of lock contention try { if (File.Exists(cacheFilePath)) { semaphore.Release(); return(cacheFilePath); } } catch { semaphore.Release(); throw; } try { CheckDisposed(); var newWidth = Convert.ToInt32(newSize.Width); var newHeight = Convert.ToInt32(newSize.Height); Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath)); if (string.IsNullOrWhiteSpace(options.BackgroundColor)) { using (var originalImage = new MagickWand(originalImagePath)) { originalImage.CurrentImage.ResizeImage(newWidth, newHeight); DrawIndicator(originalImage, newWidth, newHeight, options); originalImage.CurrentImage.CompressionQuality = quality; originalImage.SaveImage(cacheFilePath); return(cacheFilePath); } } else { using (var wand = new MagickWand(newWidth, newHeight, options.BackgroundColor)) { using (var originalImage = new MagickWand(originalImagePath)) { originalImage.CurrentImage.ResizeImage(newWidth, newHeight); wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0); DrawIndicator(wand, newWidth, newHeight, options); wand.CurrentImage.CompressionQuality = quality; wand.SaveImage(cacheFilePath); return(cacheFilePath); } } } } finally { semaphore.Release(); } }
public void DrawingWandCircleTest() { using (var wand = new MagickWand(TestImageBackdrop)) { //wand.NewImage(400, 200, new PixelWand("white")); //wand.OpenImage(TestImageBackdrop); using (var draw = new DrawingWand()) { using (PixelWand pixel = new PixelWand()) { pixel.Color = "red"; draw.StrokeColor = pixel; pixel.Color = "black"; pixel.Opacity = 0.3; draw.FillColor = pixel; draw.DrawCircle(400, 400, 300, 300); pixel.Color = "transparent"; draw.StrokeColor = pixel; pixel.Color = "white"; draw.FillColor = pixel; draw.Font = "Verdana"; draw.FontSize = 120; draw.FontStyle = FontStyleType.NormalStyle; draw.TextAlignment = TextAlignType.LeftAlign; draw.FontWeight = FontWeightType.BoldStyle; draw.TextAntialias = true; draw.DrawAnnotation(10, 100, "Media Browser"); draw.FillColor = pixel; wand.CurrentImage.DrawImage(draw); } } //Debug.WriteLine(wand.GetNumberImages()); //wand.Image.TrimImage(10); wand.SaveImage(Path.Combine(SaveDirectory, "logo_extent.jpg")); } }
public void ResizeImageTestDir() { var path = @"D:\Video\TV\Carnivàle\Season 2\Carnivàle - 2x09 - Lincoln Highway DVD.jpg"; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.CurrentImage.ResizeImage(400, 150); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.jpg")); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.png")); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.webp")); } }
public void ResizeImageTest() { var path = TestImageLogo; Assert.IsTrue(File.Exists(path)); using (var wand = new MagickWand(path)) { wand.CurrentImage.ResizeImage(400, 150); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.jpg")); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.png")); wand.SaveImage(Path.Combine(SaveDirectory, "TestResize.webp")); } }
public void MediaBrowserWandOverlayTests() { using (var wand = new MagickWand(TestImageBackdrop)) { using (MagickWand wandComposit = new MagickWand(TestImageLogo)) { //draw.FillOpacity = 0.5; wand.CurrentImage.OverlayImage(CompositeOperator.AtopCompositeOp, 560, 660, wandComposit.CurrentImage.Width, wandComposit.CurrentImage.Height, wandComposit); } wand.SaveImage(Path.Combine(SaveDirectory, "TestImageBackdrop.jpg")); } }