ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Properties | List of all members
ImageResizer.ImageJob Class Reference

Public Member Functions

 ImageJob (object source, object dest, Instructions instructions)
 
 ImageJob (object source, object dest, Instructions instructions, bool disposeSource, bool addFileExtension)
 
 ImageJob (Stream sourceStream, Stream destStream, Instructions instructions)
 
 ImageJob (string sourcePath, string destPath, Instructions instructions)
 
 ImageJob (object source, IEnumerable< string > requestedImageInfo)
 Creates an ImageJob that won't run a full build - it will only do enough work in order to supply the requested data fields. More...
 
 ImageJob (string sourcePath, string destPath, ResizeSettings settings)
 
 ImageJob (Stream sourceStream, Stream destStream, ResizeSettings settings)
 
 ImageJob (object source, object dest, ResizeSettings settings)
 
 ImageJob (object source, object dest, ResizeSettings settings, bool disposeSource, bool addFileExtension)
 
ImageJob Build ()
 Shorthand method for ImageBuilder.Current.Build(this) More...
 
ImageJob CreateDir ()
 Sets CreateParentDirectory to true. Provided for easy chaining so you can do one-liners. new ImageJob(source,dest,settings).CreateDir().Build() More...
 
string ResolveTemplatedPath (string path, ImageResizer.Util.PathUtils.VariableResolverCallback resolver)
 Internal use only. Resolves the specified (potenetially templated) path into a physical path. Applies the AddFileExtension setting using the 'ext' variable. Supplies the guid, settings.*, filename, path, and originalExt variables. The resolver method should supply 'ext', 'width', and 'height' (all of which refer to the final image). If AllowDestinationPathVariables=False, only AddFileExtenson will be processed. More...
 

Properties

List< string > RequestedInfo [get, set]
 A list of strings which define properties that can be returned to the caller. "source.width", "source.height", "result.ext", "result.mime" are the most commonly used. Defaults to none More...
 
Dictionary< string, object > ResultInfo [get, set]
 A dictionary of key/value pairs provided along with the result. More...
 
object Source [get, set]
 The source image's physical path, app-relative virtual path, or a Stream, byte array, Bitmap, VirtualFile, IVirtualFile, HttpPostedFile, or HttpPostedFileBase instance. More...
 
object Dest [get, set]
 The destination Stream, physical path, or app-relative virtual path. If a Bitmap instance is desired, set this to typeof(System.Drawing.Bitmap). The result will be stored in .Result More...
 
object Result [get, set]
 The result if a Bitmap, BitmapSource, or IWICBitmapSource instance is requested. More...
 
int SourceWidth [get]
 The width, in pixels, of the first frame or page in the source image file More...
 
int SourceHeight [get]
 The height, in pixels, of the first frame or page in the source image file More...
 
string ResultFileExtension [get]
 The correct file extension for the resulting file stream, without a leading dot. Will be null if the result is not an encoded image. More...
 
string ResultMimeType [get]
 The correct mime type for the resulting file stream, without a leading dot. Will be null if the result is not an encoded image. More...
 
ResizeSettings Settings [get, set]
 The image processing settings More...
 
Instructions Instructions [get, set]
 The image processing instructions More...
 
bool DisposeSourceObject [get, set]
 If true, and if 'source' is a IDisposable instead like Bitmap or Stream instance, it will be disposed after it has been used. Defaults to true. More...
 
bool ResetSourceStream [get, set]
 If true, and if 'source' is seekable, the stream will be reset to its previous position after being read. Always true for HttpPostedFile(Base) instances, defaults to false for all others. More...
 
bool DisposeDestinationStream [get, set]
 If true, and if 'dest' is a Stream instance, it will be disposed after the image has been written. Defaults to false. More...
 
string FinalPath [get, set]
 Contains the final physical path to the image (if 'dest' was a path - null otherwise) More...
 
string SourcePathData [get, set]
 If 'source' contains any path-related data, it is copied into this member for use by format detetction code, so decoding can be optimized. May be a physical or virtual path, or just a file name. More...
 
bool AddFileExtension [get, set]
 If true, the appropriate extension for the encoding format will be added to the destination path, and the result will be stored in FinalPath in physical path form. More...
 
bool AllowDestinationPathVariables [get, set]
 If true (the default), destination paths can include variables that are expanded during the image build process. Ex. Dest = "~/folder/&lt;guid>.&lt;ext>" will expand to "C:\WWW\App\folder\1ddadaadaddaa75da75ad34ad33da3a.jpg". More...
 
bool CreateParentDirectory [get, set]
 Defaults to false. When true, the parent directory of the destination filename will be created if it doesn't already exist. More...
 

Detailed Description

Definition at line 10 of file ImageJob.cs.

Constructor & Destructor Documentation

ImageResizer.ImageJob.ImageJob ( object  source,
IEnumerable< string >  requestedImageInfo 
)
inline

Creates an ImageJob that won't run a full build - it will only do enough work in order to supply the requested data fields.

Parameters
source
requestedImageInfoPass null to use "source.width","source.height", "result.ext","result.mime".

Definition at line 41 of file ImageJob.cs.

42  {
43  this.Source = source;
44  this.Dest = typeof(IDictionary<string, object>);
45  this.RequestedInfo = new List<string>(requestedImageInfo == null ? new string[]{"source.width","source.height", "result.ext","result.mime"} : requestedImageInfo);
46  this.ResultInfo = new Dictionary<string, object>();
47  this.Instructions = new Instructions();
48  }
Instructions Instructions
The image processing instructions
Definition: ImageJob.cs:144

Member Function Documentation

ImageJob ImageResizer.ImageJob.Build ( )
inline

Shorthand method for ImageBuilder.Current.Build(this)

Returns

Definition at line 68 of file ImageJob.cs.

68  {
69  return ImageBuilder.Current.Build(this);
70  }
ImageJob ImageResizer.ImageJob.CreateDir ( )
inline

Sets CreateParentDirectory to true. Provided for easy chaining so you can do one-liners. new ImageJob(source,dest,settings).CreateDir().Build()

Returns

Definition at line 226 of file ImageJob.cs.

226  {
227  CreateParentDirectory = true;
228  return this;
229  }
bool CreateParentDirectory
Defaults to false. When true, the parent directory of the destination filename will be created if it ...
Definition: ImageJob.cs:217
string ImageResizer.ImageJob.ResolveTemplatedPath ( string  path,
ImageResizer.Util.PathUtils.VariableResolverCallback  resolver 
)
inline

Internal use only. Resolves the specified (potenetially templated) path into a physical path. Applies the AddFileExtension setting using the 'ext' variable. Supplies the guid, settings.*, filename, path, and originalExt variables. The resolver method should supply 'ext', 'width', and 'height' (all of which refer to the final image). If AllowDestinationPathVariables=False, only AddFileExtenson will be processed.

Parameters
path
resolver
Returns

Definition at line 241 of file ImageJob.cs.

241  {
243  //Only add the extension if requested when variables are turned off.
244  return PathUtils.MapPathIfAppRelative(path + (AddFileExtension ? ("." + resolver("ext")) : ""));
245  }
246  if (this.AddFileExtension) path = path + ".<ext>";
247  path = PathUtils.ResolveVariablesInPath(path, delegate(string p) {
248  //Let the 'resolver' passed to this method take precedence - we provide default values.
249  string result = resolver(p);
250  if (result != null) return result;
251  //GUID in lowercase hexadecimal with no hyphens
252  if ("guid".Equals(p, StringComparison.OrdinalIgnoreCase))
253  return Guid.NewGuid().ToString("N", NumberFormatInfo.InvariantInfo);
254  //Access to the settings collection
255  string settingsPrefix = "settings.";
256  if (p.StartsWith(settingsPrefix, StringComparison.OrdinalIgnoreCase)) {
257  string subName = p.Substring(settingsPrefix.Length);
258  return Instructions[subName];
259  }
260  //Access to the instructions collection
261  string instructionsPrefix = "instructions.";
262  if (p.StartsWith(instructionsPrefix, StringComparison.OrdinalIgnoreCase))
263  {
264  string subName = p.Substring(instructionsPrefix.Length);
265  return Instructions[subName];
266  }
267  if ("filename".Equals(p,StringComparison.OrdinalIgnoreCase)){
268  if (SourcePathData == null) throw new ImageProcessingException("You cannot use the <filename> variable in a job that does not have a source filename, such as with a Stream or Bitmap instance");
269  return Path.GetFileNameWithoutExtension(SourcePathData);
270  }
271  if ("dir".Equals(p, StringComparison.OrdinalIgnoreCase)) {
272  if (SourcePathData == null) throw new ImageProcessingException("You cannot use the <dir> variable in a job that does not have a source filename, such as with a Stream or Bitmap instance");
273  return Path.GetDirectoryName(SourcePathData); //Just remove the last segment
274  }
275  if ("path".Equals(p, StringComparison.OrdinalIgnoreCase)) {
276  if (SourcePathData == null) throw new ImageProcessingException("You cannot use the <path> variable in a job that does not have a source filename, such as with a Stream or Bitmap instance");
277  return PathUtils.RemoveExtension(SourcePathData); //Just remove the last segment
278  }
279  if ("originalext".Equals(p, StringComparison.OrdinalIgnoreCase)) {
280  if (SourcePathData == null) throw new ImageProcessingException("You cannot use the <originalext> variable in a job that does not have a source filename, such as with a Stream or Bitmap instance");
281  return PathUtils.GetExtension(SourcePathData); //Just remove the last segment
282  }
283 
284 
285  return null;
286  });
287  return PathUtils.MapPathIfAppRelative(path);
288  }
string SourcePathData
If &#39;source&#39; contains any path-related data, it is copied into this member for use by format detetctio...
Definition: ImageJob.cs:189
bool AddFileExtension
If true, the appropriate extension for the encoding format will be added to the destination path...
Definition: ImageJob.cs:198
Instructions Instructions
The image processing instructions
Definition: ImageJob.cs:144
bool AllowDestinationPathVariables
If true (the default), destination paths can include variables that are expanded during the image bui...
Definition: ImageJob.cs:208

Property Documentation

bool ImageResizer.ImageJob.AddFileExtension
getset

If true, the appropriate extension for the encoding format will be added to the destination path, and the result will be stored in FinalPath in physical path form.

Definition at line 198 of file ImageJob.cs.

Referenced by ImageResizer.ImageJob.ResolveTemplatedPath().

bool ImageResizer.ImageJob.AllowDestinationPathVariables
getset

If true (the default), destination paths can include variables that are expanded during the image build process. Ex. Dest = "~/folder/&lt;guid>.&lt;ext>" will expand to "C:\WWW\App\folder\1ddadaadaddaa75da75ad34ad33da3a.jpg".

Definition at line 208 of file ImageJob.cs.

Referenced by ImageResizer.ImageJob.ResolveTemplatedPath().

bool ImageResizer.ImageJob.CreateParentDirectory
getset

Defaults to false. When true, the parent directory of the destination filename will be created if it doesn't already exist.

Definition at line 217 of file ImageJob.cs.

Referenced by ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin.BuildJob(), ImageResizer.ImageBuilder.BuildJob(), and ImageResizer.ImageJob.CreateDir().

object ImageResizer.ImageJob.Dest
getset

The destination Stream, physical path, or app-relative virtual path. If a Bitmap instance is desired, set this to typeof(System.Drawing.Bitmap). The result will be stored in .Result

Definition at line 96 of file ImageJob.cs.

Referenced by ImageResizer.ImageBuilder.Build(), ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin.BuildJob(), and ImageResizer.ImageBuilder.BuildJob().

bool ImageResizer.ImageJob.DisposeDestinationStream
getset

If true, and if 'dest' is a Stream instance, it will be disposed after the image has been written. Defaults to false.

Definition at line 169 of file ImageJob.cs.

Referenced by ImageResizer.ImageBuilder.Build().

bool ImageResizer.ImageJob.DisposeSourceObject
getset

If true, and if 'source' is a IDisposable instead like Bitmap or Stream instance, it will be disposed after it has been used. Defaults to true.

Definition at line 150 of file ImageJob.cs.

Referenced by ImageResizer.ImageBuilder.Build().

string ImageResizer.ImageJob.FinalPath
getset

Contains the final physical path to the image (if 'dest' was a path - null otherwise)

Definition at line 178 of file ImageJob.cs.

Referenced by ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin.BuildJob(), and ImageResizer.ImageBuilder.BuildJob().

Instructions ImageResizer.ImageJob.Instructions
getset

The image processing instructions

Definition at line 144 of file ImageJob.cs.

Referenced by ImageResizer.ImageJob.ImageJob().

List<string> ImageResizer.ImageJob.RequestedInfo
getset

A list of strings which define properties that can be returned to the caller. "source.width", "source.height", "result.ext", "result.mime" are the most commonly used. Defaults to none

Definition at line 75 of file ImageJob.cs.

bool ImageResizer.ImageJob.ResetSourceStream
getset

If true, and if 'source' is seekable, the stream will be reset to its previous position after being read. Always true for HttpPostedFile(Base) instances, defaults to false for all others.

Definition at line 160 of file ImageJob.cs.

Referenced by ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin.BuildJob(), ImageResizer.Plugins.WicBuilder.WicBuilderPlugin.BuildJob(), and ImageResizer.ImageBuilder.BuildJob().

object ImageResizer.ImageJob.Result
getset

The result if a Bitmap, BitmapSource, or IWICBitmapSource instance is requested.

Definition at line 107 of file ImageJob.cs.

string ImageResizer.ImageJob.ResultFileExtension
get

The correct file extension for the resulting file stream, without a leading dot. Will be null if the result is not an encoded image.

Definition at line 124 of file ImageJob.cs.

Dictionary<string, object> ImageResizer.ImageJob.ResultInfo
getset

A dictionary of key/value pairs provided along with the result.

Definition at line 80 of file ImageJob.cs.

string ImageResizer.ImageJob.ResultMimeType
get

The correct mime type for the resulting file stream, without a leading dot. Will be null if the result is not an encoded image.

Definition at line 128 of file ImageJob.cs.

ResizeSettings ImageResizer.ImageJob.Settings
getset
object ImageResizer.ImageJob.Source
getset

The source image's physical path, app-relative virtual path, or a Stream, byte array, Bitmap, VirtualFile, IVirtualFile, HttpPostedFile, or HttpPostedFileBase instance.

Definition at line 86 of file ImageJob.cs.

Referenced by ImageResizer.ImageBuilder.Build(), ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin.BuildJob(), and ImageResizer.ImageBuilder.BuildJob().

int ImageResizer.ImageJob.SourceHeight
get

The height, in pixels, of the first frame or page in the source image file

Definition at line 119 of file ImageJob.cs.

string ImageResizer.ImageJob.SourcePathData
getset

If 'source' contains any path-related data, it is copied into this member for use by format detetction code, so decoding can be optimized. May be a physical or virtual path, or just a file name.

Definition at line 189 of file ImageJob.cs.

Referenced by ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin.BuildJob(), and ImageResizer.ImageJob.ResolveTemplatedPath().

int ImageResizer.ImageJob.SourceWidth
get

The width, in pixels, of the first frame or page in the source image file

Definition at line 115 of file ImageJob.cs.


The documentation for this class was generated from the following file: