Found a very strange behaviour with Sitecore image control, take the following code
<sc:Image runat="server" ID="img" Height="200" Width="300"/>
i would expect that would render the img tag with the correct height and width, but instead it renders out this
<img src="/~/media/Images/websitename/Images/1.ashx?h=120&w=160" alt="basics" width="160" height="120">
it overrides the height and width that i set and take the image height and width.. odd indeed
luckily we have a way to overcome this without having to use custom control or having to resort to asp.net image control – we would like the support the page editor functionality.
Set the parameters explicitly
That’s right, we need to set the parameters explicitly so that it renders out the correct value.
First, remove the Height and Width attribute from the markup
<sc:Image runat="server" ID="img"/>
then in the code behind
img.Item = item; img.Field = "Big Image"; img.Parameters = "w=200&h=300";
and here’s the result
<img src="/~/media/Images/Website/Images/1.ashx?h=300&w=200" alt="basics" width="200" height="300">
Just like what i wanted.
If you’re wondering what other parameters are supported by the image control, you could find that in the Sitecore SDN