CakePHP 图像未调整大小,适合容器

CakePHP image not resizing, fitting container

在大多数现代编程语言中,可以将图像添加到您的页面,然后使用周围 div 或图像标记中的 max-height 属性调整它的大小以适合容器。 在 cakephp 中,情况并非如此。当我使用 max-height 属性时,图像保持相同大小然后被裁剪。它甚至没有 max-height 属性的尺寸。它有一些随机像素数量。 这是我的一段代码。我已经尝试了 css 的所有不同组合。有谁知道如何在 cakephp 中显示适合容器的图像?

<div style="max-height:29px;">
<?php echo $this->Html->image('/webroot/files/Users/photo/' . $user->photo, ['alt' => 'picOfme', 'max-height'=>'100%']);
 ?>
</div>

In most modern programming languages it is possible to add an image to your page and then resize it to fit a container using max-height attributes in either the surrounding div or the image tag. In cakephp this is not the case.

首先 HTML 根本不是 编程,而是一种 标记 语言。参见 Is HTML considered a programming language?

php 本身能够很好地调整和裁剪图像。 CakePHP 没有为此提供任何抽象,因为它超出了框架的范围。已经有足够的第三方库可以完成这项工作。如果您想使用 CakePHP 处理图像 try the Imagine plugin.

归根结底,您尝试做的事情与 php 或 CakePHP 完全无关。为此,我已经更正了您的标签。

the right search terms you would have found plenty of solutions already, here is one of them: CSS scale down image to fit in containing div, without specifing original size