如何计算图像的高度和宽度?我正在尝试将第一个答案中描述的图像居中:
这就是我到目前为止所尝试的:
<% 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