Fetching image cropper cropped file path

IPublished content extension for getting crop image file easily

ImageCropper datatype was once part of uComponents, but because it is so usefull, it is now included into standard Umbraco instalation.

However as much it is useful, I could not find the way to get cropped image file properly with anything that was shipped with Umbraco installation. Therefore I decided to write my own extension and to make life easier while working with ImageCropper in Umbraco.

        public static string GetCropImageUrl(this IPublishedContent media, string cropName)
        {
            string result =  string.Empty;
            if (media != null)
            {
                string filename;
                result = media.Url.Substring(0, media.Url.LastIndexOf("/"));
                filename = media.Url.Substring(media.Url.LastIndexOf("/"));
                filename = string.Concat(
                    filename.Substring(0, filename.LastIndexOf(".")),
                    "_", cropName,
                    filename.Substring(filename.LastIndexOf("."))
                    );
                result = string.Concat(result, filename);
            }
            return result;
        }
    

This is nothing by a string manipulation function which adds _cropname to a media file path.

Note

This extension method does not check whether file is created or not by cropper. It will always return a string value based on crop name parameter and media file URL path

Disclaimer

Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.


About the author

DEJAN STOJANOVIC

Dejan is a passionate Software Architect/Developer. He is highly experienced in .NET programming platform including ASP.NET MVC and WebApi. He likes working on new technologies and exciting challenging projects

CONNECT WITH DEJAN  Loginlinkedin Logintwitter Logingoogleplus Logingoogleplus

.NET

read more

JavaScript

read more

SQL/T-SQL

read more

PowerShell

read more

Comments for this article