update image processing

This commit is contained in:
Luke Pulverenti
2017-05-14 22:27:58 -04:00
parent bdc546ed85
commit 2f4f8c105e
9 changed files with 121 additions and 91 deletions

View File

@@ -130,7 +130,7 @@ namespace Emby.Drawing.ImageMagick
string.Equals(ext, ".webp", StringComparison.OrdinalIgnoreCase);
}
public void EncodeImage(string inputPath, string outputPath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
public void EncodeImage(string inputPath, ImageSize? originalImageSize, string outputPath, bool autoOrient, 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);
@@ -144,6 +144,16 @@ namespace Emby.Drawing.ImageMagick
originalImage.CurrentImage.TrimImage(10);
}
if (options.CropWhiteSpace || !originalImageSize.HasValue)
{
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));
ScaleImage(originalImage, width, height, options.Blur ?? 0);
if (autoOrient)
@@ -162,9 +172,19 @@ namespace Emby.Drawing.ImageMagick
}
else
{
using (var wand = new MagickWand(width, height, options.BackgroundColor))
using (var originalImage = new MagickWand(inputPath))
{
using (var originalImage = new MagickWand(inputPath))
if (options.CropWhiteSpace || !originalImageSize.HasValue)
{
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);