public static string GetImageCacheTag(this IImageProcessor processor, IHasImages item, ImageType imageType, int imageIndex)
        {
            var imageInfo = item.GetImageInfo(imageType, imageIndex);

            if (imageInfo == null)
            {
                return null;
            }

            return processor.GetImageCacheTag(item, imageInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the enhanced image.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="imageType">Type of the image.</param>
        /// <param name="imageIndex">Index of the image.</param>
        /// <returns>Task{System.String}.</returns>
        public async Task<string> GetEnhancedImage(IHasImages item, ImageType imageType, int imageIndex)
        {
            var enhancers = GetSupportedEnhancers(item, imageType).ToList();

            var imageInfo = item.GetImageInfo(imageType, imageIndex);

            var result = await GetEnhancedImage(imageInfo, item, imageIndex, enhancers);

            return result.Item1;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the current image path.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="type">The type.</param>
 /// <param name="imageIndex">Index of the image.</param>
 /// <returns>System.String.</returns>
 /// <exception cref="System.ArgumentNullException">
 /// imageIndex
 /// or
 /// imageIndex
 /// </exception>
 private ItemImageInfo GetCurrentImage(IHasImages item, ImageType type, int imageIndex)
 {
     return item.GetImageInfo(type, imageIndex);
 }
Exemplo n.º 4
0
        public double? GetPrimaryImageAspectRatio(IHasImages item)
        {
            var imageInfo = item.GetImageInfo(ImageType.Primary, 0);

            if (imageInfo == null || !imageInfo.IsLocalFile)
            {
                return null;
            }

            ImageSize size;

            try
            {
                size = _imageProcessor.GetImageSize(imageInfo);
            }
            catch (Exception ex)
            {
                //_logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path);
                return null;
            }

            var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary).ToList();

            foreach (var enhancer in supportedEnhancers)
            {
                try
                {
                    size = enhancer.GetEnhancedImageSize(item, ImageType.Primary, 0, size);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error in image enhancer: {0}", ex, enhancer.GetType().Name);
                }
            }

            var width = size.Width;
            var height = size.Height;

            if (width == 0 || height == 0)
            {
                return null;
            }

            var photo = item as Photo;
            if (photo != null && photo.Orientation.HasValue)
            {
                switch (photo.Orientation.Value)
                {
                    case ImageOrientation.LeftBottom:
                    case ImageOrientation.LeftTop:
                    case ImageOrientation.RightBottom:
                    case ImageOrientation.RightTop:
                        var temp = height;
                        height = width;
                        width = temp;
                        break;
                }
            }

            return width / height;
        }
Exemplo n.º 5
0
        public bool MergeImages(IHasImages item, List<LocalImageInfo> images)
        {
            var changed = false;

            foreach (var type in _singularImages)
            {
                var image = images.FirstOrDefault(i => i.Type == type);

                if (image != null)
                {
                    var currentImage = item.GetImageInfo(type, 0);

                    if (currentImage == null)
                    {
                        item.SetImagePath(type, image.FileInfo);
                        changed = true;
                    }
                    else if (!string.Equals(currentImage.Path, image.FileInfo.FullName,
                            StringComparison.OrdinalIgnoreCase))
                    {
                        item.SetImagePath(type, image.FileInfo);
                        changed = true;
                    }
                    else
                    {
                        currentImage.DateModified = _fileSystem.GetLastWriteTimeUtc(image.FileInfo);
                    }
                }
            }

            if (UpdateMultiImages(item, images, ImageType.Backdrop))
            {
                changed = true;
            }

            var hasScreenshots = item as IHasScreenshots;
            if (hasScreenshots != null)
            {
                if (UpdateMultiImages(item, images, ImageType.Screenshot))
                {
                    changed = true;
                }
            }

            return changed;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Attaches the primary image aspect ratio.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="item">The item.</param>
        /// <param name="fields">The fields.</param>
        /// <returns>Task.</returns>
        public void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item, List<ItemFields> fields)
        {
            var imageInfo = item.GetImageInfo(ImageType.Primary, 0);

            if (imageInfo == null || !imageInfo.IsLocalFile)
            {
                return;
            }

            ImageSize size;

            try
            {
                size = _imageProcessor.GetImageSize(imageInfo);
            }
            catch (Exception ex)
            {
                //_logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path);
                return;
            }

            var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary).ToList();

            foreach (var enhancer in supportedEnhancers)
            {
                try
                {
                    size = enhancer.GetEnhancedImageSize(item, ImageType.Primary, 0, size);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error in image enhancer: {0}", ex, enhancer.GetType().Name);
                }
            }

            if (size.Width > 0 && size.Height > 0)
            {
                dto.PrimaryImageAspectRatio = size.Width / size.Height;
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the current image path.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="type">The type.</param>
 /// <param name="imageIndex">Index of the image.</param>
 /// <returns>System.String.</returns>
 /// <exception cref="System.ArgumentNullException">
 /// imageIndex
 /// or
 /// imageIndex
 /// </exception>
 private ItemImageInfo GetCurrentImage(IHasImages item, ImageType type, int imageIndex)
 {
     return(item.GetImageInfo(type, imageIndex));
 }
Exemplo n.º 8
0
        private bool HasImage(IHasImages item, ImageType type)
        {
            var image = item.GetImageInfo(type, 0);

            // if it's a placeholder image then pretend like it's not there so that we can replace it
            return image != null && !image.IsPlaceholder;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the image path.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="item">The item.</param>
        /// <returns>System.String.</returns>
        private ItemImageInfo GetImageInfo(ImageRequest request, IHasImages item)
        {
            var index = request.Index ?? 0;

            return(item.GetImageInfo(request.Type, index));
        }
Exemplo n.º 10
0
        public bool MergeImages(IHasImages item, List<LocalImageInfo> images)
        {
            var changed = false;

            foreach (var type in _singularImages)
            {
                var image = images.FirstOrDefault(i => i.Type == type);

                if (image != null)
                {
                    var currentImage = item.GetImageInfo(type, 0);

                    if (currentImage == null || !string.Equals(currentImage.Path, image.FileInfo.FullName, StringComparison.OrdinalIgnoreCase))
                    {
                        item.SetImagePath(type, image.FileInfo);
                        changed = true;
                    }
                }
            }

            var backdrops = images.Where(i => i.Type == ImageType.Backdrop).ToList();
            if (backdrops.Count > 0)
            {
                var foundImages = images.Where(i => i.Type == ImageType.Backdrop)
                    .Select(i => i.FileInfo)
                    .ToList();

                if (foundImages.Count > 0)
                {
                    if (item.AddImages(ImageType.Backdrop, foundImages))
                    {
                        changed = true;
                    }
                }
            }

            var hasScreenshots = item as IHasScreenshots;
            if (hasScreenshots != null)
            {
                var foundImages = images.Where(i => i.Type == ImageType.Screenshot)
                    .Select(i => i.FileInfo)
                    .ToList();

                if (foundImages.Count > 0)
                {
                    if (item.AddImages(ImageType.Screenshot, foundImages))
                    {
                        changed = true;
                    }
                }
            }

            return changed;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Attaches the primary image aspect ratio.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="item">The item.</param>
        /// <returns>Task.</returns>
        public void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item)
        {
            var imageInfo = item.GetImageInfo(ImageType.Primary, 0);

            if (imageInfo == null)
            {
                return;
            }

            var path = imageInfo.Path;

            // See if we can avoid a file system lookup by looking for the file in ResolveArgs
            var dateModified = imageInfo.DateModified;

            ImageSize size;

            try
            {
                size = _imageProcessor.GetImageSize(path, dateModified);
            }
            catch (FileNotFoundException)
            {
                _logger.Error("Image file does not exist: {0}", path);
                return;
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path);
                return;
            }

            dto.OriginalPrimaryImageAspectRatio = size.Width / size.Height;

            var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary).ToList();

            foreach (var enhancer in supportedEnhancers)
            {
                try
                {
                    size = enhancer.GetEnhancedImageSize(item, ImageType.Primary, 0, size);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error in image enhancer: {0}", ex, enhancer.GetType().Name);
                }
            }

            dto.PrimaryImageAspectRatio = size.Width / size.Height;
        }