<% 
page = Request.Querystring("height")
strKlasor = "resim/"
strResimYolu = Server.MapPath(strKlasor) &"\"
Const strAvtWidth = 800 'Kırpılacak Avatar Genişliği (px)
Const strAvtHeight = 600 'Kırpılacak Avatar Yüksekliği (px)
Const strPre = "thumb_" 'Küçük resimler için ön ek


Function GenerateGUID()
	Dim TypeLib
    Set TypeLib = CreateObject("Scriptlet.TypeLib")
    GenerateGUID = Mid(CStr(TypeLib.Guid), 2, 36)
    Set TypeLib = Nothing
End Function 

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="js/jquery-pack.js"></script>
	<script type="text/javascript" src="js/jquery.imgareaselect.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>

<% If Session("kaydet") = True Then %>
<%
atikmadde = Session("buyukResim")
Set fso = CreateObject("Scripting.FileSystemObject")
Set File = fso.GetFile(Server.MapPath(""&atikmadde&""))
File.Delete
%>
Resim url'si : <input type="text" name="imgKucuk" size="120" value="admin/upload/<%=Session("kucukResim")%>" />
<br />
<img src="<%=Session("kucukResim")%>" alt="Küçük Resim"/>

<%
session.Abandon
End If %>

<% If Session("edit") = True Then %>
<script type="text/javascript">
function preview(img, selection) { 
	var scaleX = <%=strAvtWidth%> / selection.width; 
	var scaleY = <%=strAvtHeight%> / selection.height; 
	
	$('#thumbnail + div > img').css({ 
		width: Math.round(scaleX * <%=Session("aktif_gen")%>) + 'px', 
		height: Math.round(scaleY * <%=Session("aktif_yuk")%>) + 'px',
		marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px', 
		marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' 
	});
	$('#x1').val(selection.x1);
	$('#y1').val(selection.y1);
	$('#x2').val(selection.x2);
	$('#y2').val(selection.y2);
	$('#w').val(selection.width);
	$('#h').val(selection.height);
} 

$(document).ready(function () { 
	$('#save_thumb').click(function() {
		var x1 = $('#x1').val();
		var y1 = $('#y1').val();
		var x2 = $('#x2').val();
		var y2 = $('#y2').val();
		var w = $('#w').val();
		var h = $('#h').val();
		if(x1=="" || y1=="" || x2=="" || y2=="" || w=="" || h==""){
			alert("You must make a selection first");
			return false;
		}else{
			return true;
		}
	});
}); 

$(window).load(function () { 
	$('#thumbnail').imgAreaSelect({ onSelectChange: preview }); 
});

</script>
		<div align="center">
			<img src="<%= strKlasor & Session("aktif_res") %>" style="float: left; margin-right: 10px;" id="thumbnail" alt="Create Thumbnail" />

			<br style="clear:both;"/>
			<form name="thumbnail" action="<%= Request.ServerVariables("SCRIPT_NAME") %>?is=kaydet" method="post">
				<input type="hidden" name="x1" value="" id="x1" />
				<input type="hidden" name="y1" value="" id="y1" />
				<input type="hidden" name="x2" value="" id="x2" />
				<input type="hidden" name="y2" value="" id="y2" />
				<input type="hidden" name="w" value="" id="w" />
				<input type="hidden" name="h" value="" id="h" />
				<input type="submit" name="upload_thumbnail" value="Resmi kaydet" id="save_thumb" />
			</form>
		</div>
	
<% End If %>
<% 
If Session("kaydet") = True Then 
else
If Session("edit") = True Then
else
%>
<form name="photo" enctype="multipart/form-data" action="<%= Request.ServerVariables("SCRIPT_NAME") %>?is=upl" method="post">
<input type="file" name="image" size="30" /><input type="submit" name="upload" value=" Dosyayı servera gönder..." onClick="this.value='Yükleniyor..'"/>
</form>
<%
end if
end if
If Request("is") = "upl" Then
	Session("kaydet") = False
	Set Upload = Server.CreateObject("Persits.Upload")
	Upload.OverwriteFiles = False
	Upload.Save strResimYolu
	
	
	For Each File in Upload.Files 
		strYeniAd = GenerateGUID() & File.ext 
		File.Copy strResimYolu & strYeniAd
		File.Delete 
		Session("aktif_res") = strYeniAd
		Session("edit") = True
	Next
	Set Upload = Nothing
	
	Set jpeg = Server.CreateObject("Persits.Jpeg")
		jpeg.Open( strResimYolu & strYeniAd )
		Session("aktif_gen") = jpeg.Width
		Session("aktif_yuk") = jpeg.Height
	Set jpeg = Nothing
	Response.Redirect Request.ServerVariables("SCRIPT_NAME")
	
		ElseIf Request("is") = "kaydet" Then
		strKX1 = Request.Form("x1")
		strKY1 = Request.Form("y1")
		strKX2 = Request.Form("x2")
		strKY2 = Request.Form("y2")
		Set Jpeg = Server.CreateObject("Persits.Jpeg")
		Jpeg.Open strResimYolu & Session("aktif_res")
		Jpeg.Width = Jpeg.OriginalWidth 
		Jpeg.Height = Jpeg.OriginalHeight
		Jpeg.Quality = 80
		Jpeg.Crop strKX1, strKY1, strKX2, strKY2

		strBuyuk = strKlasor & Session("aktif_res")
		strKucuk = strKlasor & strPre & Session("aktif_res")
		Session("edit") = False
		Session("buyukResim") = strKlasor & Session("aktif_res")
		Dim strJpgUzanti,splJpgUzanti
		splJpgUzanti = Split(Session("aktif_res"),".")
		strJpgUzanti = splJpgUzanti(0) &".jpg"
		Jpeg.Save strResimYolu & strPre & strJpgUzanti
		Session("kucukResim") = strKlasor & strPre & strJpgUzanti
		Session("kaydet") = True
		Set Jpeg = Nothing
		Response.Redirect Request.ServerVariables("SCRIPT_NAME")
		End If




If Request("is") = "restart" Then
session.Abandon
response.Redirect("default.asp")
end if
%>