0
如何获得图像高度和宽度的计算?我试图像第一个答案说明中心的图像:SilverStripe获取图像宽度/高度的一半
How to make an image center (vertically & horizontally) inside a bigger div
这是我迄今为止尝试:
<% control ProfileImage %>
<% if getOrientation = 1 %>
<img src="$URL" style="margin-left: -{$Width/2)}px" class="portrait"/>
<% else_if getOrientation = 2 %>
<img src="$URL" class="landscape"/>
<% end_if %>
<% end_control %>
决定性线的输出是:
<img src="/assets/Uploads/picture.jpg" style="margin-left: -{154/2)}px" class="portrait"/>
然后我试着写一个自己的功能:
class Profile extends Page{
//...
function GetHalfWidth(){
return ($this->ProfileImage->Width)/2;
}
//...
}
,但我得到以下错误,当我尝试在前台查看页面:
[Notice] Trying to get property of non-object