-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadimg.php
78 lines (56 loc) · 1.75 KB
/
loadimg.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
<?php
session_start();
// make sure everything is ok
if (!isset($_GET['url']) || !preg_match('%^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?.*\.(png|jpg|gif)$%i', rawurldecode($_GET['url'])) || !isset($_GET['tok']) || !isset($_SESSION['priv']) || !isset($_GET['pub']) || isset($_GET['tok']) && isset($_SESSION['priv']) && isset($_GET['pub']) && $_GET['pub'] != md5($_GET['tok'] . 'SALT_1' . $_SESSION['priv'] . 'SALT_2'))
die();
$url = preg_replace('/ /','%20',rawurldecode($_GET['url']));
$handle = fopen($url, "r");
if (!$handle)
die($handle);
$contents = "";
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$im = imagecreatefromstring($contents);
$oW = imagesx($im);
$oH = imagesy($im);
if ($oW > 640)
{
$nW = 640;
$nH = round($oH * $nW / $oW);
$newim = imagecreatetruecolor($nW, $nH);
imagecopyresized($newim, $im, 0,0,0,0, $nW,$nH,$oW,$oH);
imagedestroy($im);
$im = $newim;
$oW = $nW;
$oH = $nH;
}
$numShreds = (isset($_GET['nshreds'])&&intval($_GET['nshreds'])!=0)?intval($_GET['nshreds']):20;
if ($oW/$numShreds<6)
$numShreds = floor($oW/6);
if ($oW%$numShreds != 0)
{
$nW = floor($oW/$numShreds)*$numShreds;
$nH = round($oH * $nW / $oW);
$newim = imagecreatetruecolor($nW, $nH);
imagecopyresized($newim, $im, 0,0,0,0, $nW,$nH,$oW,$oH);
imagedestroy($im);
$im = $newim;
$oW = $nW;
$oH = $nH;
}
$shredWidth = intval($oW/$numShreds);
$outim = imagecreatetruecolor($oW, $oH);
$shOrder = array();
for ($i=0; $i<$numShreds; ++$i)
$shOrder[] = $i;
shuffle($shOrder);
for ($i=0; $i<$numShreds; ++$i)
{
imagecopy($outim, $im, $i*$shredWidth, 0, $shOrder[$i]*$shredWidth, 0, $shredWidth, $oH);
}
header('Content-Type: image/png');
imagepng($outim);
imagedestroy($im);
imagedestroy($outim);