-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaling_tool.html
278 lines (218 loc) · 6.91 KB
/
scaling_tool.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Scaling Tool</title>
<meta name="description" content="Tool for establishing the PPI of an Image based on some known dimensions.">
<meta name="author" content="Jordan Slaman">
<link rel="shortcut icon" href="http://static.jordanslaman.com/img/me/favicon.ico">
<!-- External CSS Dependancies -->
<link rel="stylesheet" href="src/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="src/jquery-ui-1.11.4/jquery-ui.min.css">
<!-- External JS Dependancies -->
<script src="src/jquery-1.11.3.min.js"></script>
<script src="src/jquery-ui-1.11.4/jquery-ui.min.js"></script>
<script src="src/bootstrap/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style type="text/css">
body {
background: #ddd;
}
#container {
background: #fff;
min-height: 800px;
margin: 40px auto;
border: 1px #ccc dashed;
}
#box {
width:247px;
height:150px;
background: rgba(10, 255, 225, 0.2);
border: 1px black dashed;
z-index: 1;
top:75px;
left:292px;
}
#image {
width:100%;
min-height: 620px;
background-size:100%;
background-repeat: no-repeat;
}
#inner {
}
</style>
</head>
<body>
<div id="container" class="container">
<div class="row" style="padding:25px;">
<div class="col-md-6">
<label for="imageURL">Image Location</label>
<input type="url" class="form-control" id="imageURL" value="http://scaler.jordanslaman.com/img/scale_test.jpeg">
<!--
<p></p>
<label for="fileUpload">Upload New</label>
<input type="file" id="fileUpload">
<p class="help-block">This feature is not yet implemented.</p>
-->
</div>
<div class="col-md-2">
<button id="load" class="btn btn-default" style="margin-top: 25px;">Load</button>
</div>
</div>
<div class="row">
<div id="imageContainer" style="/* padding:20px; */" >
<div id="image" class="col-md-12" style="background-image: url('http://scaler.jordanslaman.com/img/scale_test.jpeg');">
<div id="box">
<div id="inner" style="margin:15px;">
<input id="innerWidth" value="58.6" style="width:40px;"></input>mm wide
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">
<label for="imageTitle">Image Title</label>
<input type="text" class="form-control" id="imageTitle" value="iPhone 5S">
</div>
<div class="col-md-6">
<label for="imageCaption">Image Caption</label>
<input type="text" class="form-control" id="imageCaption" value="iPhone 5S Test Image!"></input>
</div>
<div class="col-md-2">
<label for="imageGallery">Image Gallery</label>
<input type="text" class="form-control" id="imageGallery" value="zgallery1">
</div>
<div class="col-md-2 checkbox">
<label style="padding-top:20px;">
<input type="checkbox" id="hideThumb" > Hide Thumbnail
</label>
</div>
<input type="text" style="display:none;" id="scaleFactor" value="262.6236734693877"></input>
</div>
<div class="row" style="padding-top:15px;">
<div class="col-md-12">
<pre id="output"></pre>
</div>
</div>
</div>
<script type="text/javascript">
$("#box").draggable({
containment: "imageContainer"
});
$("#box").resizable({
resize: function( event, ui ) {
updateScaleFactor()
}
});
var imageNaturalWidth;
updateURL(); //Loads an image and sets it's natural dimensions.
function updateURL() {
$("#image").css({
'background-image' :' url("'+$("#imageURL").val()+'")'
});
/*
// Create new offscreen image to get true (not rendered) image dimensions, replaced with .width() for our implementation.
var theImage = new Image();
theImage.src = $("#imageURL").val();
theImage.onload = function() {
imageNaturalWidth = theImage.naturalWidth;
}
*/
updateScaleFactor();
}
function updateScaleFactor() {
//how many blue boxes are in the image?
boxes_per_image = $("#image").width()/$("#box").width();
//The amount of blue boxes by their size in mm
mm_per_image = boxes_per_image * $("#innerWidth").val();
$("#scaleFactor").val(mm_per_image);
updateText();
}
function updateText() {
var hideThumb = "";
if($("#hideThumb").is(':checked')){
hideThumb = " style=\"display:none;\"";
}
$('#output').html('<li'+hideThumb+'><br><a href="'+$("#imageURL").val()+'" title="'+$("#imageTitle").val()+'" class="zoombox '+$("#imageGallery").val()+'" data-scalefactor="'+$("#scaleFactor").val()+'" data-description="'+$("#imageCaption").val()+'"><br><img src="'+$("#imageURL").val()+'" alt="'+$("#imageCaption").val()+'" /><br></a><br></li>');
}
$('#load').click(updateURL);
$('#imageURL').change(updateText);
$('#imageGallery').change(updateText);
$('#imageTitle').change(updateText);
$('#imageCaption').change(updateText);
$('#hideThumb').change(updateText);
$("#innerWidth").change(updateText);
//Keyboard Support
$(document).keydown(function(e) {
switch(e.which) {
case 37: // left
if (!e.shiftKey) {
if (!e.altKey){
$("#box").css('left', '-=1px');
} else {
$("#box").css('width', '-=1px');
}
} else {
if (!e.altKey){
$("#box").css('left', '-=10px');
} else {
$("#box").css('width', '-=10px');
}
}
break;
case 38: // up
if (!e.shiftKey) {
if (!e.altKey){
$("#box").css('top', '-=1px');
} else {
$("#box").css('height', '-=1px');
}
} else {
if (!e.altKey){
$("#box").css('top', '-=10px');
} else {
$("#box").css('height', '-=10px');
}
}
break;
case 39: // right
if (!e.shiftKey) {
if (!e.altKey){
$("#box").css('left', '+=1px');
} else {
$("#box").css('width', '+=1px');
}
} else {
if (!e.altKey){
$("#box").css('left', '+=10px');
} else {
$("#box").css('width', '+=10px');
}
}
break;
case 40: // down
if (!e.shiftKey) {
if (!e.altKey){
$("#box").css('top', '+=1px');
} else {
$("#box").css('height', '+=1px');
}
} else {
if (!e.altKey){
$("#box").css('top', '+=10px');
} else {
$("#box").css('height', '+=10px');
}
}
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
</script>
</body>
</html>