-
Notifications
You must be signed in to change notification settings - Fork 0
/
glitch.php
93 lines (67 loc) · 2.5 KB
/
glitch.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
<?php
/**
* Created by JetBrains PhpStorm.
* User: wss-world
* Date: 9/26/13
* Time: 5:19 PM
* To change this template use File | Settings | File Templates.
*/
require_once ('glitchPhoto.php');
header('Content-Type: application/json');
ini_set('gd.jpeg_ignore_warning', 1);
$id = $_POST['id'];
if($id) {
$glitch = new glitchPhoto($id);
if ($_POST['action'] == 'create') {
$dataPhoto = json_decode($_POST['dataPhoto']);
$dataPhotoGlitch = $glitch->createGlitchFriends($dataPhoto);
$data = array(
'dataPhotoGlitch' => $dataPhotoGlitch
);
echo json_encode($data);
} elseif($_POST['action'] == 'update-glitch') {
$index = $_POST['index'];
$urlPhoto = $glitch->updateGlitchFriend($index);
$data = array(
'src' => $urlPhoto
);
echo json_encode($data);
} elseif($_POST['action'] == 'post') {
$upload_url = $_POST['upload_url'];
$type = $_POST['name_img'];
$resFileName = './/images//'.$id.'//mosaic-'.$type.'.jpg';
if (file_exists($resFileName)) {
unlink($resFileName);
}
$mosaic = imagecreatetruecolor(1026, 1026);
$white = imagecolorallocate($mosaic, 0xFF, 0xFF, 0xFF);
imagefill($mosaic, 1, 1, $white);
$indexFileName = 0;
$fileName = './/images//'.$id.'//'.$indexFileName.'-'.$type.'.jpg';
for($i = 0; $i < 5; $i++) {
for($j = 0; $j < 5; $j++) {
$img = imagecreatefromjpeg($fileName);
imagecopy($mosaic, $img, $j * 200 + (6 * $j + 1), $i * 200 + (6 * $i + 1), 0, 0, imagesx($img), imagesy($img));
imagedestroy($img);
$indexFileName++;
$fileName = './/images//'.$id.'//'.$indexFileName.'-'.$type.'.jpg';
}
}
imagejpeg($mosaic, './/images//'.$id.'//mosaic-'.$type.'.jpg', 75);
$post_params['photo'] = '@.//images//'.$id.'//mosaic-'.$type.'.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result);
$mess = array (server => $result->server, photo=> $result->photo, hash => $result->hash);
echo json_encode($mess);
} else {
echo 'erorr2222';
}
} else {
echo 'error';
}