Example #1
0
        private string GenerateThumbnailId(string thumbnailId = null)
        {
            var ext = Common.GetImageExtension(FileFormat);

            if (ext == null)
            {
                throw new MediaUnsupportedException(string.Format("FileFormat: {0}", FileFormat));
            }

            string id;

            if (!string.IsNullOrEmpty(thumbnailId))
            {
                id = thumbnailId;
            }
            else
            {
                var fileName = new StringBuilder(Path.GetFileNameWithoutExtension(_source.Name));
                var ci       = CultureInfo.InvariantCulture;
                fileName.Append("[");
                fileName.Append(Size.Width.ToString(ci));
                fileName.Append("x");
                fileName.Append(Size.Height.ToString(ci));

                if (ColorManagement != null)
                {
                    fileName.Append(",cm(");
                    var sourceProfile = ColorManagement.GetProfile(ColorManagement, _source.Params.PixelFormat.ColorSpace);
                    if (sourceProfile != null)
                    {
                        fileName.Append(AjaxControls.Common.CalculateMD5(Encoding.UTF8.GetBytes(sourceProfile.Description)));
                    }

                    var targetProfile = ColorManagement.GetTargetProfile(ColorManagement);
                    if (targetProfile != null)
                    {
                        fileName.Append(",");
                        fileName.Append(AjaxControls.Common.CalculateMD5(Encoding.UTF8.GetBytes(targetProfile.Description)));
                    }

                    fileName.Append(")");
                }

                if (ResizeMode != Transforms.ResizeMode.Resize)
                {
                    fileName.Append(",");
                    fileName.Append(ResizeMode);
                }

                fileName.Append("]");

                id = fileName.ToString().ToLowerInvariant();
            }

            return(string.Format("{0}.{1}", id, ext));
        }