/// <summary>
        /// Retrieves the width, height and aspect ratio of a media item.
        /// Returns 0 for both if either of the properties are missing.
        /// </summary>
        public static MediaSize GetMediaSize(IPublishedContent media, int newWidth = 0)
        {
            var result = new MediaSize {
                Width = 0, Height = 0, Ratio = 1.0M
            };

            if (media.HasProperty("UmbracoWidth") && media.HasProperty("UmbracoHeight"))
            {
                var mediaWidth  = media.Value <int>("UmbracoWidth");
                var mediaHeight = media.Value <int>("UmbracoHeight");
                var mediaRatio  = Decimal.Divide(mediaHeight, mediaWidth);

                result.Width  = newWidth > 0 ? newWidth : mediaWidth;
                result.Height = newWidth > 0 ? (int)(newWidth * mediaRatio) : mediaHeight;
                result.Ratio  = mediaRatio;
            }

            return(result);
        }
        /// <summary>
        /// Retrieves the width, height and aspect ratio of a specific crop.
        /// </summary>
        public static MediaSize GetCropSize(IPublishedContent media, string crop, int newWidth = 0)
        {
            var result = new MediaSize {
                Width = 0, Height = 0, Ratio = 1.0M
            };

            var cropperValue = media.Value <ImageCropperValue>("UmbracoFile");
            var cropData     = cropperValue != null?cropperValue.GetCrop(crop) : null;

            if (cropData != null)
            {
                var cropWidth  = cropData.Width;
                var cropHeight = cropData.Height;
                var cropRatio  = Decimal.Divide(cropHeight, cropWidth);

                result.Width  = newWidth > 0 ? newWidth : cropWidth;
                result.Height = newWidth > 0 ? (int)(newWidth * cropRatio) : cropHeight;
                result.Ratio  = cropRatio;
            }

            return(result);
        }
 private static string GetOutputTag(string size1x, string size2x, string altText, MediaSize sizes)
 {
     return(string.Format("<img srcset=\"{0} 2x\" src=\"{1}\" width=\"{3}\" height=\"{4}\" alt=\"{2}\" />", size2x, size1x, altText, sizes.Width, sizes.Height));
 }
 private static string GetOutputTag(string image, string altText, MediaSize sizes)
 {
     return(string.Format("<img src=\"{0}\" width=\"{2}\" height=\"{3}\" alt=\"{1}\" />", image, altText, sizes.Width, sizes.Height));
 }