Index.asp
<%
Server.ScriptTimeout = 320
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder(Server.MapPath("/cropping/pix/"))
%>
<html>
<head>
<script language="javascript">
function preloadImages() {
var d=document; if(d.images){ if(!d.p) d.p=new Array();
var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}
</script>
</head>
<body onLoad="preloadImages(<%
for each img in fo.files
Response.Write "'
http://mdk/Cropping/Resizer.asp?img=" & img.name & "width=200',"
next
%>'')">
<div align="center">
<% if Request.QueryString("Save") = "" and Request.QueryString("Cropped") = "" then %>
<% if Request.QueryString("F.x") = "" and Request.QueryString("S.x") = "" and Request.QueryString("Image") = "" Then %>
<h3>Pictures avaiable to crop'n'resize:</h3>
<Form Method="post" Action="Upload.asp" ENCTYPE="multipart/form-data">
<input type="FILE" name="FILE1" size="30">
<input type="submit" value="Upload">
</Form>
<%
Set Jpeg = Server.CreateObject("Persits.Jpeg")
if Request.QueryString("Delete") <> "" then
fs.DeleteFile(Server.MapPath("pix/" & Request.QueryString("Delete")))
Response.Redirect("index.asp")
end if
for each x in fo.files
ext = Split(x.name,".")
if Lcase(ext(ubound(ext))) = "jpg" then
Response.Write "<table><tr><td>"
Response.write "<a href=""?Image=" & x.name & """><img width=""200"" src=""Resizer.asp?img=" & x.name & "&width=200""></a>"
Response.Write "</td><td>"
Jpeg.Open(Server.MapPath("pix/" & x.name))
Response.Write "<li>" & x.name
Response.Write "<li>" & formatnumber(x.size/1024,2) & " kilobytes"
Response.Write "<li>" & Jpeg.width & " x " & Jpeg.height & " pixels"
Response.Write "<li><a OnClick=""return confirm('Are you shure you want to\n\nDELETE?');"" href=""?delete=" & x.name & """>Delete</a>"
Response.Write "<li><a href=""pix/" & x.name & """>Show normal size</a>"
Response.Write "</td></tr></table>"
end if
next
%>
<% elseif Request.QueryString("F.x") = "" and Request.QueryString("S.x") = "" and Request.QueryString("Image") <> "" Then %>
<form method="get">
<h3>Use the Mouse to locate the <u>Upper Left</u> Cropping Coordinate</h3>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#FF0000">
<tr>
<td><input type="image" name="F" src="pix/<%=Request.QueryString("Image")%>"></td>
</tr>
</table>
<input type="hidden" name="Image" value="<%=Request.QueryString("Image")%>">
</form>
<% elseif Request.QueryString("F.x") <> "" and Request.QueryString("S.x") = "" and Request.QueryString("Image") <> "" Then %>
<form method="get">
<h3>Use the Mouse to locate the <u>Lower Right</u> Cropping Coordinate</h3>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#FF0000">
<tr>
<td><input type="image" name="S" src="Cropper.asp?Image=<%=Request.QueryString("Image")%>&F.y=<%=Request.QueryString("F.y")%>&F.x=<%=Request.QueryString("F.x")%>"></td>
</tr>
</table>
<input type="hidden" name="Image" value="<%=Request.QueryString("Image")%>">
<input type="hidden" name="F.x" value="<%=Request.QueryString("F.X")%>">
<input type="hidden" name="F.Y" value="<%=Request.QueryString("F.Y")%>">
</form>
<% elseif Request.QueryString("F.x") <> "" and Request.QueryString("S.x") <> "" and Request.QueryString("Image") <> "" Then %>
<form method="get">
<h3>If the crop is as you want it... click Save, Else use BackSpace to Undo the last opperations</h3>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#FF0000">
<tr>
<td><input type="image" name="S" src="Cropper.asp?Image=<%=Request.QueryString("Image")%>&F.y=<%=Request.QueryString("F.y")%>&F.x=<%=Request.QueryString("F.x")%>&S.x=<%=Request.QueryString("S.x")%>&S.y=<%=Request.QueryString("S.y")%>"></td>
</tr>
</table>
<input type="hidden" name="Image" value="<%=Request.QueryString("Image")%>">
<input type="hidden" name="F.x" value="<%=Request.QueryString("F.X")%>">
<input type="hidden" name="F.y" value="<%=Request.QueryString("F.Y")%>">
<input type="hidden" name="S.x" value="<%=Request.QueryString("S.X")%>">
<input type="hidden" name="S.y" value="<%=Request.QueryString("S.Y")%>">
<input type="submit" name="Save" value="Save Cropped Image">
</form>
<% End if %>
<% Elseif Request.QueryString("Cropped") = "1" then %>
<img src="<%=Request.QueryString("Image")%>"><br>
Compressed <%=Request.QueryString("Q")%>%<br>
Rightclick to "save as"
<%
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open(Server.MapPath(Request.QueryString("Image")))
Else
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open(Server.MapPath("pix/" & Request.QueryString("Image")))
'Crop
Jpeg.Crop Request.QueryString("F.x"),Request.QueryString("F.y"),(Cint(Request.QueryString("S.x")) + Cint(Request.QueryString("F.x"))),(Cint(Request.QueryString("F.y")) + Cint(Request.QueryString("S.y")))
'Save
Jpeg.Quality = 100
Jpeg.Save Server.MapPath("pix/" & Request.QueryString("Image"))
'Resize if > 650
Jpeg.Open(Server.MapPath("pix/" & Request.QueryString("Image")))
If Jpeg.Width > 650 then
Jpeg.Width = 650
Jpeg.Height = Jpeg.OriginalHeight * Jpeg.Width / Jpeg.OriginalWidth
end if
Jpeg.Save Server.MapPath("pix/" & Request.QueryString("Image"))
'End Resize
set fso = Server.CreateObject("Scripting.FileSystemObject")
set fil = fso.GetFile(Server.MapPath("pix/" & Request.QueryString("Image")))
FileSize = fil.Size
Do while FileSize >= 40*1024
Jpeg.Open(Server.MapPath("pix/" & Request.QueryString("Image")))
Jpeg.Quality = 100 - Quality
Jpeg.Save Server.MapPath("Temp.jpg")
set fso = Server.CreateObject("Scripting.FileSystemObject")
set fil = fso.GetFile(Server.MapPath("Temp.jpg"))
FileSize = fil.Size
Response.Write FileSize & "<br>"
Quality = Quality + 1
Loop
Jpeg.Open(Server.MapPath("pix/" & Request.QueryString("Image")))
Jpeg.Quality = 100 - Quality
Jpeg.Save Server.MapPath("pix/" & Request.QueryString("Image"))
Response.Redirect("index.asp")'"?Cropped=1&Image=" & Request.QueryString("Image") & "&Q=" & Quality)
End if
%>
</div>
</body>
</html>