Type DefaultEncoder
Namespace ImageResizer.Plugins.Basic
Interfaces IEncoder, IQuerystringPlugin, IPlugin, IFileSignatureProvider
Provides basic encoding functionality for Jpeg, png, and gif output. Allows adjustable Jpeg compression, but doesn't implement indexed PNG files or quantized GIF files.
Methods
- AddImageExtension
- GetContentTypeFromImageFormat
- GetExtensionFromImageFormat
- GetImageCodeInfo
- GetImageFormatFromExtension
- GetImageFormatFromPhysicalPath
- GetOriginalFormat
- GetRequestedFormat
- IsValidOutputFormat
- SaveBmp
- SaveGif
- SaveJpeg
- SavePng
Properties
Public instance methods
bool IsValidOutputFormat(ImageFormat f)
Returns true if the this encoder supports the specified image format
Public static methods
void AddImageExtension(string extension, ImageFormat matchingFormat)
string GetContentTypeFromImageFormat(ImageFormat format)
Supports Png, Jpeg, Gif, Bmp, and Tiff. Throws a ArgumentOutOfRangeException if not png, jpeg, gif, bmp, or tiff
string GetExtensionFromImageFormat(ImageFormat format)
Returns an string instance from the specfied ImageFormat. First matching entry in imageExtensions is used.
Returns null if not recognized.
ImageCodecInfo GetImageCodeInfo(string mimeType)
Returns the first ImageCodeInfo instance with the specified mime type. Returns null if there are no matches.
ImageFormat GetImageFormatFromExtension(string ext)
Returns an ImageFormat instance from the specfied file extension. Extensions lie sometimes, just a guess.
returns null if not recognized.
ImageFormat GetImageFormatFromPhysicalPath(string path)
Returns the ImageFormat enumeration value based on the extension in the specified physical path. Extensions can lie, just a guess.
ImageFormat GetOriginalFormat(object original)
Attempts to determine the ImageFormat of the source image. First attempts to parse the path, if a string is present in original.Tag. (or if 'original' is a string)
Falls back to using original.RawFormat. Returns null if both 'original' is null.
RawFormat has a bad reputation, so this may return unexpected values, like MemoryBitmap or something in some situations.
Parameters
-
object
original - The source image that was loaded from a stream, or a string path
ImageFormat GetRequestedFormat(string format, ImageFormat defaultValue)
Tries to parse an ImageFormat from the settings.Format value.
If an unrecogized format is specified, returns null.
If an unsupported format is specified, it is returned.
If *no* format is specified, returns defaultValue.
void SaveBmp(Image img, Stream target)
void SaveGif(Image img, Stream target)
void SaveJpeg(Image b, Stream target, int quality)
Saves the specified image to the specified stream using jpeg compression of the specified quality.
Parameters
-
Image
b -
Stream
target -
int
quality - A number between 0 and 100. Defaults to 90 if passed a negative number. Numbers over 100 are truncated to 100. 90 is a *very* good setting.
void SavePng(Image img, Stream target)
Saves the image in png form. If Stream 'target' is not seekable, a temporary MemoryStream will be used to buffer the image data into the stream
Public properties
string Extension get;
Returns the default file extesnion for OutputFormat
string MimeType get;
Returns the default mime-type for the OutputFormat
ImageFormat OutputFormat get; set;
If you set this to anything other than Gif, Png, or Jpeg, it will throw an exception. Defaults to Jpeg
int Quality get; set;
0..100 value. The Jpeg compression quality. 90 is the best setting. Not relevant in Png or Gif compression
bool SupportsTransparency get;
Returns true if the desired output type supports transparency.