Sitefinity CMS

Files Helper Classes Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Generic Content Based Modules > Images and Documents > Files > Files Helper Classes

Glossary Item Box

There is a helper class available for files in the Images and Documents module: ImagesHelper.

 

The ImagesHelper class (Telerik.Cms.Engine  assembly) generates thumbnails, saves an image to stream and checks if an item is browsable:

Class ImagesHelper Copy Code
public static Image GenerateThumbnail(int width, int height, Image image)
public static Image GenerateThumbnail(int width, int height, Image image, bool keepProportions)
public static Image GenerateThumbnail(int width, int height, Image image, bool keepProportions, bool decreaseOnly)
public static void SaveImageToStream(Image image, MemoryStream stream, string mimeType)
public static bool IsBrowserImage(IContent content)
public static bool IsBrowserImage(IThumbnail thumbnail)
public static bool IsBrowserImage(string extension)

 

  • The method GenerateThumbnail generates a thumbnail for a given image within a framework created by the specified width and height parameters. The method has three overloads:

    • The first overload creates a thumbnail with the exact values of the width and height parameters.
    • The second overload has a boolean parameter - keep proportions - that specifies whether the image should be kept in its original size, and thus not fit the specified framework (keepProportions equal to true) or the image should be distorted so that it fits the framework specified by the width and height values (keepProportions equal to false). In the latter case the image would either be increased or decreased to fit in. 
    • The third overload of the GenerateThumbnail method passes a third parameter: decreaseOnly. It is of type boolean, and, when true, allows the image to be changed only when the size needs to be decreased because it is too big for the framework. If the image is smaller, the size would not be increased.

      For better understanding of how these methods work, here is some more information: he first two overloads call the third one with five parameters but the extra parameters are with default values:

      • The GenerateThumbnail(int width, int height, Image image) method returns the following:  
        ImagesHelper.GenerateThumbnail(width, height, image, true, false)
      • The GenerateThumbnail(int width, int height, Image image, bool keepProportions) method returns the following:  
        ImagesHelper.GenerateThumbnail(width, height, image, keepProportions, false)

 

  • The IsBrowserImage method checks if the passed parameter is browsable - this could be an image, a content item or an extension. The overload methods for the image and content item parameters retrieve the extension of the parameter and pass it to the corresponding overload, IsBrowserImage(string extension), which checks the type of extension and returns a boolean value: true if browsable.


  • The SaveImageToStream method changes the extension of the passed image. There are four possible values for the mimeType parameter: .bmp, .gif, .jpeg, .png.

 

See Also