title: SilverStripe get half of image width/height
body: <p>how can I get calculate with image height and width? I am trying to center an image like described in the first answer:</p>
  
  <p><a href="https://stackoverflow.com/questions/388180/how-to-make-an-image-center-vertically-horizontally-inside-a-bigger-div">How to make an image center (vertically &amp; horizontally) inside a bigger div</a></p>
  
  <p>That's what I have tried so far:</p>
  
  <pre><code>&lt;% control ProfileImage %&gt;
      &lt;% if getOrientation = 1 %&gt;
          &lt;img src="$URL" style="margin-left: -{$Width/2)}px" class="portrait"/&gt;
      &lt;% else_if getOrientation = 2 %&gt;
          &lt;img src="$URL" class="landscape"/&gt;
      &lt;% end_if %&gt;
  &lt;% end_control %&gt;
  </code></pre>
  
  <p>The output of the decisive line is:</p>
  
  <pre><code>&lt;img src="/assets/Uploads/picture.jpg" style="margin-left: -{154/2)}px" class="portrait"/&gt;
  </code></pre>
  
  <p>Then I tried to write an own function:</p>
  
  <pre><code>class Profile extends Page{
  //...
  function GetHalfWidth(){
      return ($this-&gt;ProfileImage-&gt;Width)/2;
  }
  //...
  }
  </code></pre>
  
  <p>But I get the following error when I try to view the page in the frontend:</p>
  
  <pre><code>[Notice] Trying to get property of non-object
  </code></pre>