tklustig
(Kipp Thomas)
1
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']); ?>
jacmoe
(Jacob Moen)
2
<?= Html::img('@web/pictures/bweiss.jpg', [
'alt' => 'pic not found',
'width' => '20px',
'height' => '20px'
]); ?>
tklustig
(Kipp Thomas)
3
Ur solution won’t help, but this will:
$pic = Html::img('@web/pictures/bweiss.jpg' , ['alt' => 'pic not found', 'style' => 'width:50px;height: 50px']);
jacmoe
(Jacob Moen)
4
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.
jacmoe
(Jacob Moen)
5
Do you get any errors when you follow my advice ?
Which is the "right way to do it".
tklustig
(Kipp Thomas)
6
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…
jacmoe
(Jacob Moen)
7
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. 
jacmoe
(Jacob Moen)
8
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.