|
|
14 years ago | |
|---|---|---|
| src | 14 years ago | |
| .gitattributes | 14 years ago | |
| .gitignore | 14 years ago | |
| README.md | 14 years ago | |
README.md
ImageProcessor
ImageProcessor is a library for on the fly processing of image files using Asp.Net
The library architecture is highly extensible and allows for easy extension.
Core plugins at present include:
- Resize
- Crop
- Quality (The quality to set the output for jpeg files)
- Filter (Image filters including sepia, greyscale, blackwhite, lomograph)
- Vignette
- Format (Sets the output format)
- Alpha (Sets opacity)
The library consists of two binaries: ImageProcessor.dll and ImageProcessor.Web.dll.
ImageProcessor.dll contains all the core functionality that allows for image manipulation via the ImageFactory class. This has a fluent API which allows you to easily chain methods to deliver the desired output.
e.g.
// Read a file and resize it.
var photoBytes = File.ReadAllBytes(file);
var before = DateTime.Now;
var quality = 90;
var format = ImageFormat.Jpeg;
var thumbnailSize = 150;
byte[] resized;
using (var inStream = new MemoryStream(photoBytes))
{
using (var outStream = new MemoryStream())
{
using (ImageFactory imageFactory = new ImageFactory())
{
// Load, resize and save an image.
imageFactory.Load(inStream).Format(format).Quality(quality).Resize(thumbnailSize, 0).Save(outStream);
}
resized = outStream.ToArray();
}
}
ImageProcessor.Web.dll contains a HttpModule which captures internal and external requests automagically processing them based on values captured through querystring parameters.
Using the HttpModule requires no code writing at all. Just reference the binaries and add the relevant sections to the web.config
Image requests suffixed with QueryString parameters will then be processed and cached to the server allowing for easy and efficient parsing of following requests.
e.g.
<img src="/images.yourimage.jpg?width=200" alt="your resized image"/>
Will resize your image to 200px wide whilst keeping the correct aspect ratio.