ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Protected Member Functions | List of all members
ImageResizer.Plugins.PsdComposer.PsdComposerPlugin Class Reference
Inheritance diagram for ImageResizer.Plugins.PsdComposer.PsdComposerPlugin:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.PsdComposer.PsdComposerPlugin:
Collaboration graph
[legend]

Public Member Functions

IPlugin Install (Config c)
 Installs the plugin in the specified Config instance. The plugin must handle all the work of loading settings, registering the plugin etc. More...
 
bool Uninstall (Config c)
 Uninstalls the plugin. Should reverse all changes made during Install More...
 
bool FileExists (string virtualPath, NameValueCollection queryString)
 Returns true if the specified file and querystring indicate a PSD composition request More...
 
IVirtualFile GetFile (string virtualPath, NameValueCollection queryString)
 Returns a virtual file instance for the specified specified file and querystring, if they indicate a PSD composition request. Otherwise, null is returned. More...
 
IEnumerable< string > GetSupportedQuerystringKeys ()
 If the plugin reads any values from the querystring, the names of the keys should be specified here. This information is required so that the HttpModule knows when to handle an image request. More...
 
IEnumerable< string > GetSupportedFileExtensions ()
 If the plugin adds support for new file extensions (such as "psd"), they should be returned by this method. More...
 
Stream ComposeStream (string virtualPath, NameValueCollection queryString)
 Returns a stream to the composed file, encoded in the format requested by the querystring or fake extension More...
 
System.Drawing.Bitmap ComposeBitmap (string virtualPath, NameValueCollection queryString)
 Returns a Bitmap instance of the composed result More...
 
Size GetPsdDimensions (string virtualPath, NameValueCollection queryString)
 Returns the size of the PSD More...
 
IList< IPsdLayerGetAllLayers (string virtualPath, NameValueCollection queryString)
 Returns a collection of all the layers for the specified file (memcached) More...
 
IList< IPsdLayerGetVisibleTextLayers (string virtualPath, NameValueCollection queryString)
 Returns a collection of all visible text layers for the file (memcached). Useful for building image maps More...
 

Protected Member Functions

bool isStrictMode ()
 
IPsdRenderer GetSelectedRenderer (NameValueCollection queryString)
 Returns the renderer object selected in the querystring More...
 
KeyValuePair< Size, IList
< IPsdLayer > > 
GetFileMetadata (string virtualPath, NameValueCollection queryString)
 Returns a collection of all the layers for the specified file and the size of the file (memcached) More...
 
bool IsPathPSDToCompose (string virtualPath, NameValueCollection queryString=null)
 True if the file is a .psd.jpeg, .psd.png, etc file. More...
 

Detailed Description

Definition at line 23 of file PsdComposerPlugin.cs.

Member Function Documentation

System.Drawing.Bitmap ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.ComposeBitmap ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns a Bitmap instance of the composed result

Parameters
id
Returns

Definition at line 123 of file PsdComposerPlugin.cs.

123  {
124  //Renderer object
125  IPsdRenderer renderer = GetSelectedRenderer(queryString);
126 
127  //Bitmap we will render to
128  System.Drawing.Bitmap b = null;
129 
130  MemCachedFile file = MemCachedFile.GetCachedVirtualFile(StripFakeExtension(virtualPath),c.Pipeline, new NameValueCollection());
131  using (Stream s = file.GetStream()) {
132  //Time just the parsing/rendering
133  Stopwatch swRender = new Stopwatch();
134  swRender.Start();
135 
136  IList<IPsdLayer> layers = null;
137  Size size = Size.Empty;
138  //Use the selected renderer to parse the file and compose the layers, using this delegate callback to determine which layers to show.
139  b = renderer.Render(s, out layers, out size, BuildLayerCallback(queryString), BuildModifyLayerCallback(queryString));
140 
141  //Save layers & size for later use
142  file.SetSubkey("layers_" + renderer.ToString(), layers);
143  file.SetSubkey("size_" + renderer.ToString(), size);
144 
145  //How fast?
146  swRender.Stop();
147  trace("Using encoder " + renderer.ToString() + ", rendering stream to a composed Bitmap instance took " + swRender.ElapsedMilliseconds.ToString() + "ms");
148  }
149 
150 
151  return b;
152  }
IPsdRenderer GetSelectedRenderer(NameValueCollection queryString)
Returns the renderer object selected in the querystring
Stream ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.ComposeStream ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns a stream to the composed file, encoded in the format requested by the querystring or fake extension

Parameters
id
Returns

Definition at line 94 of file PsdComposerPlugin.cs.

94  {
95 
96  Stopwatch sw = new Stopwatch();
97  sw.Start();
98 
99 
100  System.Drawing.Bitmap b = ComposeBitmap(virtualPath, queryString);
101  //Memory stream for encoding the file
102  MemoryStream ms = new MemoryStream();
103  //Encode image to memory stream, then seek the stream to byte 0
104  using (b) {
105  //Use whatever settings appear in the URL
106  IEncoder encoder = c.Plugins.GetEncoder(new ImageResizer.ResizeSettings(queryString), virtualPath);
107  encoder.Write(b, ms);
108  ms.Seek(0, SeekOrigin.Begin); //Reset stream for reading
109  }
110 
111 
112  sw.Stop();
113  trace("Total time, including encoding: " + sw.ElapsedMilliseconds.ToString() + "ms");
114 
115  return ms;
116  }
System.Drawing.Bitmap ComposeBitmap(string virtualPath, NameValueCollection queryString)
Returns a Bitmap instance of the composed result
Represents the settings which will be used to process the image. Extends NameValueCollection to provi...
An image encoder. Exposes methods for suitability checking, encoding, transparency compatibility chec...
Definition: IEncoder.cs:13
bool ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.FileExists ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns true if the specified file and querystring indicate a PSD composition request

Parameters
virtualPath
queryString
Returns

Implements ImageResizer.Plugins.IVirtualImageProvider.

Definition at line 46 of file PsdComposerPlugin.cs.

46  {
47  return IsPathPSDToCompose(virtualPath,queryString) && c.Pipeline.FileExists(StripFakeExtension(virtualPath),new NameValueCollection());
48  }
bool IsPathPSDToCompose(string virtualPath, NameValueCollection queryString=null)
True if the file is a .psd.jpeg, .psd.png, etc file.
IList<IPsdLayer> ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.GetAllLayers ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns a collection of all the layers for the specified file (memcached)

Parameters
virtualPath
queryString
Returns

Definition at line 170 of file PsdComposerPlugin.cs.

170  {
171  return GetFileMetadata(virtualPath, queryString).Value;
172  }
KeyValuePair< Size, IList< IPsdLayer > > GetFileMetadata(string virtualPath, NameValueCollection queryString)
Returns a collection of all the layers for the specified file and the size of the file (memcached) ...
IVirtualFile ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.GetFile ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns a virtual file instance for the specified specified file and querystring, if they indicate a PSD composition request. Otherwise, null is returned.

Parameters
virtualPath
queryString
Returns

Implements ImageResizer.Plugins.IVirtualImageProvider.

Definition at line 57 of file PsdComposerPlugin.cs.

57  {
58  if (IsPathPSDToCompose(virtualPath, queryString) && c.Pipeline.FileExists(StripFakeExtension(virtualPath), new NameValueCollection()))
59  return new PsdVirtualFile(virtualPath, queryString, this);
60  else
61  return null;
62  }
bool FileExists(string virtualPath, NameValueCollection queryString)
Returns true if (a) A registered IVirtualImageProvider says it exists, or (b) if the VirtualPathProvi...
PipelineConfig Pipeline
Access and modify settings related to the HttpModule pipline. Register URL rewriting hooks...
Definition: Config.cs:93
bool IsPathPSDToCompose(string virtualPath, NameValueCollection queryString=null)
True if the file is a .psd.jpeg, .psd.png, etc file.
KeyValuePair<Size,IList<IPsdLayer> > ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.GetFileMetadata ( string  virtualPath,
NameValueCollection  queryString 
)
inlineprotected

Returns a collection of all the layers for the specified file and the size of the file (memcached)

Parameters
virtualPath
queryString
Returns

Definition at line 179 of file PsdComposerPlugin.cs.

179  {
180  Stopwatch sw = new Stopwatch();
181  sw.Start();
182 
183 
184  //Renderer object
185  IPsdRenderer renderer = GetSelectedRenderer(queryString);
186  //File
187  MemCachedFile file = MemCachedFile.GetCachedVirtualFile(StripFakeExtension(virtualPath), c.Pipeline, new NameValueCollection());
188  //key
189  string layersKey = "layers_" + renderer.ToString();
190  string sizeKey = "size_" + renderer.ToString();
191 
192  //Try getting from the cache first
193  IList<IPsdLayer> layers = file.GetSubkey(layersKey) as IList<IPsdLayer>;
194  Size size = file.GetSubkey(sizeKey) is Size ? (Size)file.GetSubkey(sizeKey) : Size.Empty;
195  if (layers == null) {
196  //Time just the parsing
197  Stopwatch swRender = new Stopwatch();
198  swRender.Start();
199 
200  layers = renderer.GetLayersAndSize(file.GetStream(), out size);
201 
202  //Save to cache for later
203  file.SetSubkey(layersKey, layers);
204  file.SetSubkey(sizeKey, size);
205  //How fast?
206  swRender.Stop();
207  trace("Using decoder " + renderer.ToString() + ",parsing file and enumerating layers took " + swRender.ElapsedMilliseconds.ToString() + "ms");
208  }
209 
210 
211  sw.Stop();
212  trace("Total time for enumerating, including file reading: " + sw.ElapsedMilliseconds.ToString(NumberFormatInfo.InvariantInfo) + "ms");
213  return new KeyValuePair<Size,IList<IPsdLayer>>(size,layers);
214  }
IPsdRenderer GetSelectedRenderer(NameValueCollection queryString)
Returns the renderer object selected in the querystring
Size ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.GetPsdDimensions ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns the size of the PSD

Parameters
virtualPath
queryString
Returns

Definition at line 160 of file PsdComposerPlugin.cs.

160  {
161  return GetFileMetadata(virtualPath, queryString).Key;
162  }
KeyValuePair< Size, IList< IPsdLayer > > GetFileMetadata(string virtualPath, NameValueCollection queryString)
Returns a collection of all the layers for the specified file and the size of the file (memcached) ...
IPsdRenderer ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.GetSelectedRenderer ( NameValueCollection  queryString)
inlineprotected

Returns the renderer object selected in the querystring

Returns

Definition at line 83 of file PsdComposerPlugin.cs.

84  {
85  return new PsdPluginRenderer(); //There is only ONE renderer now - The Agurigma one was horrible
86  }
IEnumerable<string> ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.GetSupportedFileExtensions ( )
inline

If the plugin adds support for new file extensions (such as "psd"), they should be returned by this method.

Returns

Implements ImageResizer.Plugins.IFileExtensionPlugin.

Definition at line 69 of file PsdComposerPlugin.cs.

69  {
70  return new string[] { "psd" };
71  }
IEnumerable<string> ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.GetSupportedQuerystringKeys ( )
inline

If the plugin reads any values from the querystring, the names of the keys should be specified here. This information is required so that the HttpModule knows when to handle an image request.

Returns

Implements ImageResizer.Plugins.IQuerystringPlugin.

Definition at line 65 of file PsdComposerPlugin.cs.

65  {
66  return PsdCommandBuilder.GetSupportedQuerystringKeys();
67  }
IList<IPsdLayer> ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.GetVisibleTextLayers ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns a collection of all visible text layers for the file (memcached). Useful for building image maps

Parameters
virtualPath
queryString
Returns

Definition at line 222 of file PsdComposerPlugin.cs.

222  {
223 
224  //Get all layers
225  IList<IPsdLayer> layers = GetAllLayers(virtualPath, queryString);
226 
227 
228  Stopwatch sw = new Stopwatch();
229  sw.Start();
230  //Now, time to filter layers to those that would be showing on the image right now.
231  IList<IPsdLayer> filtered = new List<IPsdLayer>();
232 
233  //Generate a callback just like the one used in the renderer for filtering
234  ShowLayerDelegate callback = BuildLayerCallback(queryString);
235 
236  for (int i = 0; i < layers.Count; i++) {
237  if (layers[i].IsTextLayer && callback(layers[i].Index, layers[i].Name, layers[i].Visible)) {
238  filtered.Add(layers[i]);
239  }
240  }
241 
242  sw.Stop();
243  trace("Time for filtering layers: " + sw.ElapsedMilliseconds.ToString() + "ms");
244  return filtered;
245 
246  }
IList< IPsdLayer > GetAllLayers(string virtualPath, NameValueCollection queryString)
Returns a collection of all the layers for the specified file (memcached)
IPlugin ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.Install ( Config  c)
inline

Installs the plugin in the specified Config instance. The plugin must handle all the work of loading settings, registering the plugin etc.

Parameters
c
Returns

Implements ImageResizer.Plugins.IPlugin.

Definition at line 29 of file PsdComposerPlugin.cs.

29  {
30  this.c = c;
31  this.c.Plugins.add_plugin(this);
32  return this;
33  }
bool ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.IsPathPSDToCompose ( string  virtualPath,
NameValueCollection  queryString = null 
)
inlineprotected

True if the file is a .psd.jpeg, .psd.png, etc file.

Definition at line 364 of file PsdComposerPlugin.cs.

365  {
366  string fileName = System.IO.Path.GetFileName(virtualPath); //Exclude the folders, just looking at the filename here.
367  int psd = fileName.IndexOf(".psd",StringComparison.OrdinalIgnoreCase);
368  if (psd > -1){
369  //We always take the .psd. syntax
370  if (fileName.IndexOf(".psd.",StringComparison.OrdinalIgnoreCase) > -1) return true;
371 
372  if (queryString == null) queryString = c.Pipeline.ModifiedQueryString;
373  //But we only grab the .psd syntax if we detect our commands
374  foreach(string s in PsdCommandBuilder.GetSupportedQuerystringKeys()){
375  if (!string.IsNullOrEmpty(queryString[s])) return true;
376  }
377  }
378  return false;
379  }
bool ImageResizer.Plugins.PsdComposer.PsdComposerPlugin.Uninstall ( Config  c)
inline

Uninstalls the plugin. Should reverse all changes made during Install

Parameters
c
Returns

Implements ImageResizer.Plugins.IPlugin.

Definition at line 35 of file PsdComposerPlugin.cs.

35  {
36  c.Plugins.remove_plugin(this);
37  return true;
38  }

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