2

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. When I use the max-height attributes the image remains the same size and is then cropped. It doesn't even have the dimensions of the max-height attribute. It has some random pixel amount. Here is a piece of my code. I've tried all different combinations of css. Does anyone know how to do display an image in cakephp that will fit a container?

<div style="max-height:29px;">
<?php echo $this->Html->image('/webroot/files/Users/photo/' . $user->photo, ['alt' => 'picOfme', 'max-height'=>'100%']);
 ?>
</div>
floriank
  • 25,546
  • 9
  • 42
  • 66
John Hogan
  • 996
  • 1
  • 13
  • 26

1 Answers1

0

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.

First HTML is not a programming at all but a markup language. See Is HTML considered a programming language?

php itself is very well capable of resizing and cropping images. CakePHP doesn't feature any abstraction for that because it's out of the scope of the framework. There are enough third party libs that will do the job already. If you want to manipulate images using CakePHP try the Imagine plugin.

At the end of the day what you try to do has nothing to do at all with php or CakePHP. I've corrected your tags for that reason.

With 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

Community
  • 1
  • 1
floriank
  • 25,546
  • 9
  • 42
  • 66
  • Thanks for the answer burzum. I understand now that it is generating raw html. The solution I went with was not to use the cakephp html helper and loaded them in to bootstrap classes instead. I left the question up to see if there was an actual solution to cakephp html helper image tag. Thanks for the plugin suggestion though. I'll have a look at them right away. – John Hogan Feb 24 '16 at 12:29
  • You can (and should) still use the helper, just pass the right class or style information to it. Also that you use `/webroot/files/Users/photo/` makes me aware that your setup is not right. There should be no `webroot` in your path. Configure your vhost to point to the webroot folder, not the folder above, this is done for security reasons as well. – floriank Feb 24 '16 at 14:23
  • I'm using wamp and cakephp. How do I configure the vhost? Is the vhost Apache? – John Hogan Feb 25 '16 at 09:52
  • See https://www.google.com/search?q=vhost%20apache See also http://book.cakephp.org/3.0/en/deployment.html#check-your-security and http://book.cakephp.org/3.0/en/deployment.html#set-document-root And here is a lot info about deployment http://book.cakephp.org/3.0/en/installation.html#development-server – floriank Feb 25 '16 at 11:33