-
Notifications
You must be signed in to change notification settings - Fork 7
/
view.php
179 lines (177 loc) · 7.27 KB
/
view.php
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
<?php
require_once('./progressive_utils.inc.php');
$url = htmlspecialchars($_REQUEST['img']);
$scans = GetImageScans($url, $info);
$width = $info['width'];
$height = $info['height'];
$divWidth = $width * 2;
$compare = 'baseline';
if (array_key_exists('compare', $_REQUEST) && $_REQUEST['compare'] == 'original')
$compare = 'original';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="google" value="notranslate" />
<meta http-equiv="Content-Language" content="en" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/start/jquery-ui.css" type="text/css" media="all" />
<style type="text/css">
div.hidden {display:none;}
div.interactive {position:relative; top:0; left:0;}
div.cleared {float:none; clear:both;}
#slider {width:400px;}
<?php
echo "#interactive {width:{$divWidth}px;}\n";
echo "img.jpeg {width:{$width}px;height:{$height}px;}\n";
?>
</style>
</head>
<body>
<a href="https://github.com/pmeenan/progressive-scans"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<?php
if (isset($scans) && is_array($scans)) {
$scan_count = count($scans) - 1;
$mid = (int)($scan_count / 2);
echo "<h1>Progressive Jpeg Demonstration</h1>";
echo "Original Image: <a href=\"$url\">$url</a><br>";
echo "<a href=\"index.html\">New Comparison</a> - You can view any web-accessible jpeg image as a progressive comparison.";
if (array_key_exists('originalSize', $info) && array_key_exists('progressiveSize', $info) && array_key_exists('baselineSize', $info)) {
echo "<br><br><form id=\"compare\" name=\"compare\" method=\"get\" action=\"view.php\">";
echo '<input type="hidden" name="img" value="' . $_REQUEST['img'] . '">';
echo "Compare optimized progressive jpeg (" . number_format($info['progressiveSize'], 0) . " bytes) to:<br>\n";
$selected = $compare == 'baseline' ? ' checked' : '';
echo '<input type="radio" name="compare" value="baseline" onclick="this.form.submit();"' . $selected . '>Optimized baseline jpeg (' . number_format($info['baselineSize'], 0) . " bytes)<br>\n";
$selected = $compare == 'original' ? ' checked' : '';
echo '<input type="radio" name="compare" value="original" onclick="this.form.submit();"' . $selected . '>Original image (' . number_format($info['originalSize'], 0) . " bytes)<br>\n";
echo "</form>";
}
echo "<h2>Interactive View:</h2>";
echo "<p>The image on the left (or above) is the progressive image and the one on the right is top-down baseline.<br>";
echo "Move the slider to see the progression of the scans.<br>";
echo "Hover the mouse over the image to see the original image for a quick A/B comparison.</p>";
echo "<button id=\"animate\" onclick=\"ToggleAnimation();\">Start Animation</button><br>";
echo "<div id=\"interactive\">";
echo "<div id=\"slider\"></div>";
echo "<div id=\"interactive-images\">";
for ($count = 1; $count <= $scan_count; $count++) {
$visibility = 'hidden';
if ($count == $mid)
$visibility = 'visible';
echo "<div id=\"interactive-$count\" class=\"interactive $visibility\">\n";
DisplayImage($scans, $count);
echo "</div>\n";
}
echo "<div class=\"cleared\"></div></div>";
echo "</div>";
echo "<h2>Individual Images:</h2>";
for ($count = 1; $count <= $scan_count; $count++) {
echo "<div id=\"scans-$count\">\n";
DisplayImage($scans, $count);
echo "</div>\n";
}
} else {
echo "Error processing image";
}
function DisplayImage(&$scans, $count) {
global $width;
global $info;
global $compare;
$out = '';
for ($i = 0; $i < $count; $i++)
$out .= $scans[$i];
$bytes = strlen($out);
$percent = number_format(($bytes / $info['progressiveSize']) * 100, 0);
$bytesStr = number_format($bytes, 0);
echo "$count scans - $bytesStr bytes ($percent%)";
echo '<br><img class="jpeg" src="data:image/jpeg;base64,';
echo base64_encode($out);
echo '">';
if (is_file($info[$compare])) {
if ($count >= count($scans) - 1)
$bytes = $info["{$compare}Size"];
$file = fopen($info[$compare], 'rb');
if ($file) {
echo '<img class="jpeg" src="data:image/jpeg;base64,';
echo base64_encode(fread($file, $bytes));
echo '">';
fclose($file);
}
}
echo '<br><br>';
}
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script>
/*
* jQuery UI Touch Punch 0.2.2
*
* Copyright 2011, Dave Furfero
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.ui.widget.js
* jquery.ui.mouse.js
*/
(function(b){b.support.touch="ontouchend" in document;if(!b.support.touch){return;}var c=b.ui.mouse.prototype,e=c._mouseInit,a;function d(g,h){if(g.originalEvent.touches.length>1){return;}g.preventDefault();var i=g.originalEvent.changedTouches[0],f=document.createEvent("MouseEvents");f.initMouseEvent(h,true,true,window,1,i.screenX,i.screenY,i.clientX,i.clientY,false,false,false,false,0,null);g.target.dispatchEvent(f);}c._touchStart=function(g){var f=this;if(a||!f._mouseCapture(g.originalEvent.changedTouches[0])){return;}a=true;f._touchMoved=false;d(g,"mouseover");d(g,"mousemove");d(g,"mousedown");};c._touchMove=function(f){if(!a){return;}this._touchMoved=true;d(f,"mousemove");};c._touchEnd=function(f){if(!a){return;}d(f,"mouseup");d(f,"mouseout");if(!this._touchMoved){d(f,"click");}a=false;};c._mouseInit=function(){var f=this;f.element.bind("touchstart",b.proxy(f,"_touchStart")).bind("touchmove",b.proxy(f,"_touchMove")).bind("touchend",b.proxy(f,"_touchEnd"));e.call(f);};})(jQuery);
</script>
<script>
<?php
echo "\$(\"#slider\").slider({ min: 1, max: $scan_count, step: 1, value: $mid });\n";
echo "var count = $scan_count;\n";
echo "var selected = $mid;\n";
?>
var timer;
$("#slider").on("slide", function(event, ui) {
selected = ui.value;
ShowSelected();
});
$("#interactive-images").hover(
function () {
if (timer == undefined) {
$('#interactive-' + count).show();
for (i = 1; i < count; i++) {
$('#interactive-' + i).hide();
}
}
},
function () {
ShowSelected();
}
);
function ShowSelected() {
$('#interactive-' + selected).show();
for (i = 1; i <= count; i++) {
if (i != selected) {
$('#interactive-' + i).hide();
}
}
};
function IncrementProgress() {
var delay = 100;
selected++;
if (selected == count)
delay = 1000;
if (selected > count)
selected = 1;
$("#slider").slider( "value", selected );
ShowSelected();
timer = setTimeout('IncrementProgress()', delay);
};
function ToggleAnimation() {
if (timer == undefined) {
$("#animate").text('Stop Animation');
selected = 1;
$("#slider").slider( "value", selected );
ShowSelected();
timer = setTimeout('IncrementProgress()', 100);
} else {
$("#animate").text('Start Animation');
clearTimeout(timer);
timer = undefined;
}
};
</script>
</body>
</html>