Documentation > CMS Template API Library > Img > Load(Asset)

Load

Loads the specified Image based on the given asset. It must be the path of an uploaded image. It cannot have a template. If there is an attachment, you would pass the path of the attachment. If the image cannot be loaded, check the Img.HasError property

public CrownPeak.CMSAPI.Img Load(Asset)


Returns

The Img object.

Parameters

NameDescriptionType
asset The asset. CrownPeak.CMSAPI.Asset

Code Example

C#

Sample:

            
            Asset photoAsset = Asset.Load("Assets/Uploaded/Photos/myphoto.jpg");
            if (photoAsset.IsLoaded)
            {
              Img img = Img.Load(photoAsset);
              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);
              }
            }
            
            

Connect with Crownpeak