How to change width and height of an image

Hi guys, a trivial question, but however, I don’t know answer.

How can I change width and height of an image using img() method of class Html, without defining special CSS rules ?

I tried like this, but i failed:




<?= Html::img('@web/pictures/bweiss.jpg', ['alt' => 'pic not found','width=>20','height=>20']); ?>  






<?= Html::img('@web/pictures/bweiss.jpg', [

    'alt' => 'pic not found',

    'width' => '20px',

    'height' => '20px'

  ]); ?>  



Ur solution won’t help, but this will:




   $pic = Html::img('@web/pictures/bweiss.jpg' , ['alt' => 'pic not found', 'style' => 'width:50px;height: 50px']);



Don’t be silly! It works!

I’ve just tested it.

What you are doing is not as clean, using in-line CSS. The browser is more happy if you use the img properties with and height directly.

Do you get any errors when you follow my advice ?

Which is the "right way to do it".

I dont’get any error. Picture will be shown, but not with 50*50px,but rather in original size.

style must be defined additionally, at the very least for me

The right way is show above…

I have tested it in both Firefox and Chromium, so I don’t know what is wrong with your browser, or your code. :)

But if your hack works for you, I guess it works.

The difference between your method (bad method!) is that you use inline CSS and I use HTML element properties.

If you browser doesn’t honor the widht and height properties of the img element, something is wrong:

If you want to give the browser a chance to optimize better, use element properties instead of CSS where you can.