Managed API

Managed API examples

Most tasks with the managed API only require one line:

  ImageResizer.ImageBuilder.Current.Build(object source, object dest, ResizeSettings settings)


  Bitmap b = ImageResizer.ImageBuilder.Current.Build(object source, ResizeSettings settings)

Object Source

May be a physical path (C:..), an app-relative virtual path (~/folder/image.jpg), an Image, Bitmap, Stream, VirtualFile, or HttpPostedFile instance.

Object Dest

May be a Stream instance, a physical path, or an app-relative virtual path.

ResizeSetting Settings

ResizeSettings is a friendly wrapper for a query string which provides named properties as well as the regular NameValueCollection interface.

You can create one like so:

  new ResizeSettings("maxwidth=200&maxheight=200")

  new ResizeSettings(Request.QueryString)

  var r = new ResizeSettings();
  r.MaxWidth = 200;
  r.MaxHeight = 300;


  using ImageResizer;

  //Converts a jpeg into a png

                             new ResizeSettings("format=png"));

  //Crops to a square (in place)
                             new ResizeSettings("width=100&height=200&crop=auto"));

Using Variables in the Destination Path (3.1.3+)

Variables include the correct extension , random GUID , source path , source filename , , , and any settings value .

This makes many scenarios much easier to code, and reduces room for error. Many users make critical errors in their upload code, such as not sanitizing filenames, or using the original extension (immediate server highjacking, here we go).

With the new feature, a proper upload system is 3 lines:

    ImageJob i = new ImageJob(file, 
    new ResizeSettings("width=1600")); 
    i.CreateParentDirectory = true;

You can also filter values. <filename:A-Za-z0-9> keeps only the alphanumeric characters from the original filename.