public async Task DrawPlayedIndicator(MagickWand wand, ImageSize imageSize) { var x = imageSize.Width - OffsetFromTopRightCorner; using (var draw = new DrawingWand()) { using (PixelWand pixel = new PixelWand()) { pixel.Color = "#52B54B"; pixel.Opacity = 0.2; draw.FillColor = pixel; draw.DrawCircle(x, OffsetFromTopRightCorner, x - 20, OffsetFromTopRightCorner - 20); pixel.Opacity = 0; pixel.Color = "white"; draw.FillColor = pixel; draw.Font = await DownloadFont("webdings.ttf", "https://github.com/MediaBrowser/Emby.Resources/raw/master/fonts/webdings.ttf", _appPaths, _iHttpClient, _fileSystem).ConfigureAwait(false); draw.FontSize = FontSize; draw.FontStyle = FontStyleType.NormalStyle; draw.TextAlignment = TextAlignType.CenterAlign; draw.FontWeight = FontWeightType.RegularStyle; draw.TextAntialias = true; draw.DrawAnnotation(x + 4, OffsetFromTopRightCorner + 14, "a"); draw.FillColor = pixel; wand.CurrentImage.DrawImage(draw); } } }
public bool HasDefaultOptions(string originalImagePath, ImageSize size) { if (!HasDefaultOptionsWithoutSize(originalImagePath)) { return false; } if (Width.HasValue && !size.Width.Equals(Width.Value)) { return false; } if (Height.HasValue && !size.Height.Equals(Height.Value)) { return false; } if (MaxWidth.HasValue && size.Width > MaxWidth.Value) { return false; } if (MaxHeight.HasValue && size.Height > MaxHeight.Value) { return false; } return true; }
public void DrawUnplayedCountIndicator(MagickWand wand, ImageSize imageSize, int count) { var x = imageSize.Width - OffsetFromTopRightCorner; var text = count.ToString(CultureInfo.InvariantCulture); using (var draw = new DrawingWand()) { using (PixelWand pixel = new PixelWand()) { pixel.Color = "#52B54B"; pixel.Opacity = 0.2; draw.FillColor = pixel; draw.DrawCircle(x, OffsetFromTopRightCorner, x - 20, OffsetFromTopRightCorner - 20); pixel.Opacity = 0; pixel.Color = "white"; draw.FillColor = pixel; draw.Font = PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths, _fileSystem); draw.FontStyle = FontStyleType.NormalStyle; draw.TextAlignment = TextAlignType.CenterAlign; draw.FontWeight = FontWeightType.RegularStyle; draw.TextAntialias = true; var fontSize = 30; var y = OffsetFromTopRightCorner + 11; if (text.Length == 1) { x += 1; } else if (text.Length == 2) { x += 1; } else if (text.Length >= 3) { //x += 1; y -= 2; fontSize = 24; } draw.FontSize = fontSize; draw.DrawAnnotation(x, y, text); draw.FillColor = pixel; wand.CurrentImage.DrawImage(draw); } } }
/// <summary> /// Resizes a set of dimensions /// </summary> /// <param name="size">The original size object</param> /// <param name="width">A new fixed width, if desired</param> /// <param name="height">A new fixed height, if desired</param> /// <param name="maxWidth">A max fixed width, if desired</param> /// <param name="maxHeight">A max fixed height, if desired</param> /// <returns>A new size object</returns> public static ImageSize Resize(ImageSize size, double? width = null, double? height = null, double? maxWidth = null, double? maxHeight = null) { double newWidth = size.Width; double newHeight = size.Height; if (width.HasValue && height.HasValue) { newWidth = width.Value; newHeight = height.Value; } else if (height.HasValue) { newWidth = GetNewWidth(newHeight, newWidth, height.Value); newHeight = height.Value; } else if (width.HasValue) { newHeight = GetNewHeight(newHeight, newWidth, width.Value); newWidth = width.Value; } if (maxHeight.HasValue && maxHeight < newHeight) { newWidth = GetNewWidth(newHeight, newWidth, maxHeight.Value); newHeight = maxHeight.Value; } if (maxWidth.HasValue && maxWidth < newWidth) { newHeight = GetNewHeight(newHeight, newWidth, maxWidth.Value); newWidth = maxWidth.Value; } return new ImageSize { Width = newWidth, Height = newHeight }; }
/// <summary> /// Gets the cache file path based on a set of parameters /// </summary> private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, string backgroundColor) { var filename = originalPath; filename += "width=" + outputSize.Width; filename += "height=" + outputSize.Height; filename += "quality=" + quality; filename += "datemodified=" + dateModified.Ticks; filename += "f=" + format; if (addPlayedIndicator) { filename += "pl=true"; } if (percentPlayed > 0) { filename += "p=" + percentPlayed; } if (unwatchedCount.HasValue) { filename += "p=" + unwatchedCount.Value; } if (!string.IsNullOrEmpty(backgroundColor)) { filename += "b=" + backgroundColor; } filename += "v=" + Version; return GetCachePath(ResizedImageCachePath, filename, "." + format.ToString().ToLower()); }
private ImageSize GetNewImageSize(ImageProcessingOptions options, ImageSize? originalImageSize) { if (originalImageSize.HasValue) { // Determine the output size based on incoming parameters var newSize = DrawingUtils.Resize(originalImageSize.Value, options.Width, options.Height, options.MaxWidth, options.MaxHeight); return newSize; } return GetSizeEstimate(options); }
/// <summary> /// Draws the indicator. /// </summary> /// <param name="wand">The wand.</param> /// <param name="imageWidth">Width of the image.</param> /// <param name="imageHeight">Height of the image.</param> /// <param name="options">The options.</param> private void DrawIndicator(MagickWand wand, int imageWidth, int imageHeight, ImageProcessingOptions options) { if (!options.AddPlayedIndicator && !options.UnplayedCount.HasValue && options.PercentPlayed.Equals(0)) { return; } try { if (options.AddPlayedIndicator) { var currentImageSize = new ImageSize(imageWidth, imageHeight); var task = new PlayedIndicatorDrawer(_appPaths, _httpClient, _fileSystem).DrawPlayedIndicator(wand, currentImageSize); Task.WaitAll(task); } else if (options.UnplayedCount.HasValue) { var currentImageSize = new ImageSize(imageWidth, imageHeight); new UnplayedCountIndicator(_appPaths, _fileSystem).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value); } if (options.PercentPlayed > 0) { new PercentPlayedDrawer().Process(wand, options.PercentPlayed); } } catch (Exception ex) { _logger.ErrorException("Error drawing indicator overlay", ex); } }
/// <summary> /// Gets the cache file path based on a set of parameters /// </summary> /// <param name="originalPath">The path to the original image file</param> /// <param name="outputSize">The size to output the image in</param> /// <param name="quality">Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.</param> /// <param name="dateModified">The last modified date of the image</param> /// <returns>System.String.</returns> private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified) { var filename = originalPath; filename += "width=" + outputSize.Width; filename += "height=" + outputSize.Height; filename += "quality=" + quality; filename += "datemodified=" + dateModified.Ticks; return ResizedImageCache.GetResourcePath(filename, Path.GetExtension(originalPath)); }
/// <summary> /// Gets the cache file path based on a set of parameters /// </summary> private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, bool addPlayedIndicator, double? percentPlayed, int? unwatchedCount, string backgroundColor) { var filename = originalPath; filename += "width=" + outputSize.Width; filename += "height=" + outputSize.Height; filename += "quality=" + quality; filename += "datemodified=" + dateModified.Ticks; if (format != ImageOutputFormat.Original) { filename += "f=" + format; } var hasIndicator = false; if (addPlayedIndicator) { filename += "pl=true"; hasIndicator = true; } if (percentPlayed.HasValue) { filename += "p=" + percentPlayed.Value; hasIndicator = true; } if (unwatchedCount.HasValue) { filename += "p=" + unwatchedCount.Value; hasIndicator = true; } if (hasIndicator) { filename += "iv=" + IndicatorVersion; } if (!string.IsNullOrEmpty(backgroundColor)) { filename += "b=" + backgroundColor; } return GetCachePath(ResizedImageCachePath, filename, Path.GetExtension(originalPath)); }
/// <summary> /// Resizes a set of dimensions /// </summary> /// <param name="size">The size.</param> /// <param name="scaleFactor">The scale factor.</param> /// <returns>ImageSize.</returns> public static ImageSize Scale(ImageSize size, double scaleFactor) { var newWidth = size.Width * scaleFactor; return Resize(size.Width, size.Height, newWidth); }
public bool Equals(ImageSize size) { return Width.Equals(size.Width) && Height.Equals(size.Height); }
/// <summary> /// Gets the cache file path based on a set of parameters /// </summary> private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, ImageOverlay? overlay, int percentPlayed, string backgroundColor) { var filename = originalPath; filename += "width=" + outputSize.Width; filename += "height=" + outputSize.Height; filename += "quality=" + quality; filename += "datemodified=" + dateModified.Ticks; if (format != ImageOutputFormat.Original) { filename += "f=" + format; } if (overlay.HasValue) { filename += "o=" + overlay.Value; filename += "p=" + percentPlayed; } if (!string.IsNullOrEmpty(backgroundColor)) { filename += "b=" + backgroundColor; } return GetCachePath(_resizedImageCachePath, filename, Path.GetExtension(originalPath)); }
/// <summary> /// Resizes a set of dimensions /// </summary> /// <param name="size">The size.</param> /// <param name="scaleFactor">The scale factor.</param> /// <returns>ImageSize.</returns> public static ImageSize Scale(ImageSize size, double scaleFactor) { var newWidth = size.Width * scaleFactor; return(Resize(size.Width, size.Height, newWidth)); }
public bool Equals(ImageSize size) { return(Width.Equals(size.Width) && Height.Equals(size.Height)); }
public ImageSize GetEnhancedImageSize(IHasImages item, ImageType imageType, int imageIndex, ImageSize originalImageSize) { var items = GetItemsWithImages(item); if (items.Count == 0) { return originalImageSize; } if (imageType == ImageType.Thumb) { return new ImageSize { Height = ThumbImageHeight, Width = ThumbImageWidth }; } return new ImageSize { Height = SquareImageSize, Width = SquareImageSize }; }