Guest User

Untitled

a guest
May 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. [ImageOutputCache(Duration = 3000, Location = System.Web.UI.OutputCacheLocation.Client)]
  2. public void GetPic(string fn, int? w, int? h)
  3. {
  4. try
  5. {
  6. if (w > 1920) { w = 1920; }
  7. if (h > 1080) { h = 1080; }
  8. WebImage wi = new WebImage(@"~/img/" + fn);
  9. if (!h.HasValue)
  10. {
  11. Single ratio = (Single)wi.Width / (Single)wi.Height;
  12. h = (int)Math.Ceiling(wi.Width / ratio);
  13. }
  14.  
  15. wi
  16. .Resize(w.Value + 1, h.Value + 1, true, true) // Resizing the image to 100x100 px on the fly...
  17. .Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage)
  18. .Write();
  19. }
  20. catch
  21. {
  22. //new WebImage(@"~/img/default.jpg").Write();
  23. //Redirect(@"~/img/default.jpg");
  24. }
  25. }
Add Comment
Please, Sign In to add comment