-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
142 lines (118 loc) · 3.79 KB
/
index.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
<?php
$quality = [85,60,45];
$categories = [];
$images = [];
$dir = './';
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (is_dir($file) && !stristr($file, '.')) {
$categories[] = $file;
}
}
closedir($dh);
}
}
if( isset($_GET['generate']) ) {
foreach( $categories as $index => $file ) {
// Max exec time fix
//if($index < 6)
// continue;
// Retina
$thumb = new Imagick();
$thumb->readImage($file . "/header.jpg");
processImage($thumb, $file, '@2x');
// Normal
$thumb = new Imagick();
$thumb->readImage($file . "/header.jpg");
$thumb->resizeImage(1920, 644, Imagick::FILTER_LANCZOS, 1);
processImage($thumb, $file, 'no-sample', false);
// Normal
$thumb = new Imagick();
$thumb->readImage($file . "/header.jpg");
$thumb->resizeImage(1920, 644, Imagick::FILTER_LANCZOS, 1);
processImage($thumb, $file);
}
die( 'generated' );
}
function processImage(&$thumb, $file, $retina='', $compressColor = true) {
global $quality;
foreach( $quality as $q ) {
$filename = $file . "/img-". $q . $retina .".jpg";
// Strip exif data etc.
$thumb->stripImage();
// Enable progressive images
$thumb->setInterlaceScheme(Imagick::INTERLACE_PLANE);
// Remove unneeded color information
// See: http://diywpblog.com/optimizing-large-images-for-maxium-quality-and-performance/
// And: http://users.wfu.edu/matthews/misc/jpg_vs_gif/JpgCompTest/JpgChromaSub.html
if($compressColor)
$thumb->setImageProperty('jpeg:sampling-factor', '4:2:0');
if($q != 100)
$thumb->setImageCompressionQuality($q);
$thumb->writeImage($filename);
}
$thumb->clear();
$thumb->destroy();
}
function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
$c = (isset($_GET['c'])) ? $_GET['c'] : 'Belgie';
$q = (isset($_GET['q'])) ? $_GET['q'] : 100;
?>
<html>
<head>
<title>Retina compression test</title>
<style>
html,body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
#image {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-position: top center;
background-repeat: no-repeat;
background-image: url("<?=$c;?>/img-<?=$q;?>.jpg");
background-size: contain;
max-height: 644px;
}
.links {
font-size: 14px;
position: absolute;
}
a {
float: left;
width: 180px;
}
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) {
#image {
background-image: url("<?=$c;?>/img-<?=$q;?>@2x.jpg");
background-size: 1920px 644px;
}
}
</style>
</head>
<body>
<div id="image"></div>
<?php
foreach( $categories as $index => $c ) {
?>
<div class="links" style="bottom: <?=$index;?>em">
<?php
echo '<a href="" onclick="document.getElementById(\'image\').style.backgroundImage = \'url('.$c . '/header.jpg)\';return false;">original ('.human_filesize(filesize( $c . '/header.jpg' )).')</a>';
foreach ($quality as $q) {
echo '<a href="?q=' . $q . '&c=' . $c . '">' . $c . ' ' . $q . '% ('.human_filesize(filesize( $c . '/img-'.$q.'.jpg' )).')</a>';
}
echo '</div>';
}
?>
</body>
</html>