To be fair, I can’t call it very high quality because it’s just high quality and there isn’t anything higher than high, however, as I’ll discuss later, since this has a higher quality than the existing techniques for high quality resizing, I’d call it very high quality to help search engines. I’m the type of the lazy programmer who knows software engineering and doesn’t waste time reinventing the wheel, so I usually try to find solutions to existing classic problems when I’m writing code. Working on Hawraman, the engine powering Keyvan.TV, I needed to resize the poster image of videos dynamically to display them to users both on Keyvan.TV and on any third party site that uses the embedment code. Apparently, I had to create a controller that serves for dynamically resizing my images on fly and rendering them in the output. Looking for the existing solutions, I copy/pasted 4-5 different codes available on the internet, but none of them gave me a satisfactory result, so I had to invest more and write an improved code. Although I usually don’t publish posts that are already done by others, I guess this time I have to publish this one and share the code to help others when they’re searching for the solution. Yes, I know, it’s like a 1980’s blog post, but I’m an old guy! Here I implement my image resizing techniques in an ASP.NET MVC controller, however, the logic is the same for applying this technique to other types of applications including ASP.NET Web Forms or desktop applications. I have to point that the first two approaches discussed below are discussed in more details by Gunnar Peipman, Mike Borozdin, and many others (with some minor modifications), however, these approaches don’t provide the high quality that you may need for many scenarios, or at least, they couldn’t serve for my purposes.
SetupI implement my resizing techniques in different action methods in an ASP.NET MVC controller. These action methods receive the width and height of the destination image as their parameters. I can set up my routing to handle this controller, called ImageResizeController. public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
"ImageResizer",
"imageresize/{action}/{width}/{height}",
new { controller = "ImageResize", action = "Index", width = 400, height = 225 }
);
Read more: Keyvan Nayyeri
QR:
SetupI implement my resizing techniques in different action methods in an ASP.NET MVC controller. These action methods receive the width and height of the destination image as their parameters. I can set up my routing to handle this controller, called ImageResizeController. public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
"ImageResizer",
"imageresize/{action}/{width}/{height}",
new { controller = "ImageResize", action = "Index", width = 400, height = 225 }
);
Read more: Keyvan Nayyeri
QR: