Guest User

Untitled

a guest
Jun 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <% @ Language = "javascript" CodePage="1252" %>
  2. <% @ import namespace = System.Diagnostics %>
  3. <% @ import namespace = System.IO %>
  4. <%
  5.  
  6. var w = getIntMust("w")
  7. , h = getIntMust("h")
  8. , img = get("img");
  9.  
  10. if (img)
  11. if (fileExists(Server.MapPath(''),img))
  12. resizeImage(Server.MapPath(img),w,h);
  13. else
  14. throw "File " + img + " does not exist";
  15. else
  16. // TODO: some other kind of error handler?
  17. throw "No image filename provided.";
  18.  
  19.  
  20. function resizeImage(img,w,h) {
  21. var compiler = new Process();
  22. compiler.StartInfo.FileName = Server.MapPath("convert.exe");
  23. compiler.StartInfo.Arguments = " -resize "+w+"x"+h+" \"" + img + "\" jpg:-";
  24. compiler.StartInfo.UseShellExecute = false;
  25. compiler.StartInfo.RedirectStandardOutput = true;
  26. compiler.Start();
  27. Response.ContentType = "image/JPEG";
  28. Response.Write(compiler.StandardOutput.ReadToEnd());
  29. Response.End();
  30. }
  31.  
  32. function fileExists(dir,name) {
  33. return find (Directory.GetFiles(dir),function(file){
  34. return name == file.replace(/^.+\\(.+)$/,"$1");
  35. });
  36. }
  37.  
  38. function find(array,pred) {
  39. if (!array) return null;
  40. for (var i = 0; i < array.length; i++)
  41. if (pred(array[i])) return array[i];
  42. return null;
  43. }
  44.  
  45. function getIntMust(key) {
  46. var v = get(key);
  47. if (v) return v*1;
  48. else throw key + " not provided.";
  49. }
  50.  
  51. function get(key) {
  52. var v = Request.QueryString(key);
  53. if (typeof (0+v)!="string") return null;
  54. else return v;
  55. }
  56.  
  57. %>
Add Comment
Please, Sign In to add comment