Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <% @ Language = "javascript" CodePage="1252" %>
- <% @ import namespace = System.Diagnostics %>
- <% @ import namespace = System.IO %>
- <%
- var w = getIntMust("w")
- , h = getIntMust("h")
- , img = get("img");
- if (img)
- if (fileExists(Server.MapPath(''),img))
- resizeImage(Server.MapPath(img),w,h);
- else
- throw "File " + img + " does not exist";
- else
- // TODO: some other kind of error handler?
- throw "No image filename provided.";
- function resizeImage(img,w,h) {
- var compiler = new Process();
- compiler.StartInfo.FileName = Server.MapPath("convert.exe");
- compiler.StartInfo.Arguments = " -resize "+w+"x"+h+" \"" + img + "\" jpg:-";
- compiler.StartInfo.UseShellExecute = false;
- compiler.StartInfo.RedirectStandardOutput = true;
- compiler.Start();
- Response.ContentType = "image/JPEG";
- Response.Write(compiler.StandardOutput.ReadToEnd());
- Response.End();
- }
- function fileExists(dir,name) {
- return find (Directory.GetFiles(dir),function(file){
- return name == file.replace(/^.+\\(.+)$/,"$1");
- });
- }
- function find(array,pred) {
- if (!array) return null;
- for (var i = 0; i < array.length; i++)
- if (pred(array[i])) return array[i];
- return null;
- }
- function getIntMust(key) {
- var v = get(key);
- if (v) return v*1;
- else throw key + " not provided.";
- }
- function get(key) {
- var v = Request.QueryString(key);
- if (typeof (0+v)!="string") return null;
- else return v;
- }
- %>
Add Comment
Please, Sign In to add comment