Documentation > CMS Template API Library > Img > Load(String)
Load
Loads an image using the specified CMS path.
public CrownPeak.CMSAPI.Img Load(String)
Returns
The Img object.
Parameters
Name | Description | Type |
---|---|---|
path | The path: Could be an asset path or an attachment path. | System.String |
Code Example
C#
Sample:
// Load an image from an uploaded asset (no template) Img img = Img.Load("/Assets/Uploaded/Photos/myphoto.jpg"); if (!img.HasError) { Out.WriteLine("<img src=\"{0}\" width=\"{1}\" height=\"{2}\" />",photoAsset.GetLink(), img.Width, img.Height); } else { Out.WriteLine("Loading image failed. Error: {0}", img.ErrorMessage); } // Load an image from an attachment stored on the current asset Img img2 = Img.Load(asset["my_photo"]); if (!img2.HasError) { Out.WriteLine("<img src=\"{0}\" width=\"{1}\" height=\"{2}\" />",asset["my_photo"], img2.Width, img2.Height); } else { Out.WriteLine("Loading image2 failed. Error: {0}", img2.ErrorMessage); }