One way to "normalize" the appearance in different browsers is to use the "server side" to resize the image. Example using a C # controller:
public ActionResult ResizeImage(string imageUrl, int width) { WebImage wImage = new WebImage(imageUrl); wImage = WebImageExtension.Resize(wImage, width); return File(wImage.GetBytes(), "image/png"); }
where WebImage is a class in System.Web.Helpers.
WebImageExtension is defined below:
using System.IO; using System.Web.Helpers; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using System.Collections.Generic; public static class WebImageExtension { private static readonly IDictionary<string, ImageFormat> TransparencyFormats = new Dictionary<string, ImageFormat>(StringComparer.OrdinalIgnoreCase) { { "png", ImageFormat.Png }, { "gif", ImageFormat.Gif } }; public static WebImage Resize(this WebImage image, int width) { double aspectRatio = (double)image.Width / image.Height; var height = Convert.ToInt32(width / aspectRatio); ImageFormat format; if (!TransparencyFormats.TryGetValue(image.ImageFormat.ToLower(), out format)) { return image.Resize(width, height); } using (Image resizedImage = new Bitmap(width, height)) { using (var source = new Bitmap(new MemoryStream(image.GetBytes()))) { using (Graphics g = Graphics.FromImage(resizedImage)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(source, 0, 0, width, height); } } using (var ms = new MemoryStream()) { resizedImage.Save(ms, format); return new WebImage(ms.ToArray()); } } } }
Check out the InterpolationMode.HighQualityBicubic option. This is the method used by Chrome.
Now you need to publish it on the web page. Let's use a razor:
<img src="@Url.Action("ResizeImage", "Controller", new { urlImage = "<url_image>", width = 35 })" />
And it worked very well for me!
Ideally, it is better to save the image in advance in different widths using this resizing algorithm to avoid the controller process every time the image is loaded.
(Sorry for my poor English, I'm Brazilian ...)