-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimg_process.php
More file actions
59 lines (44 loc) · 1.16 KB
/
img_process.php
File metadata and controls
59 lines (44 loc) · 1.16 KB
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
<?php
require('functions.php');
$user = getFacebookUser();
if($user == 0)
{
$user_ip = $_SERVER['REMOTE_ADDR'];
d("Hacking attempt on the image processing script from user ip: $user_ip");
die('hacking attempt');
}
$cmd = $_GET['cmd'];
switch($cmd)
{
case 'square':
$img_name = urldecode($_GET['name']);
squareImage($img_name);
}
// Makes an image square
function squareImage($img_name)
{
global $user;
$img_path = escapeshellarg(getcwd() . "/upload-plugin/server/user-files/$user/files/$img_name");
// See if the image is already a square
$command = IMAGEMAGICK_IDENTIFY_PATH . " $img_path";
$img_info = explode(" ", exec($command));
$dimensions = explode("x",$img_info[2]);
$isSquare = $dimensions[0] == $dimensions[1];
if($isSquare)
{
d("The image is square, so we're returning");
echo '1';
return;
}
// This can potentially be improved ... a lot
$command = IMAGEMAGICK_PATH . " $img_path -thumbnail x200 -resize '200x<' -resize 50% -gravity center -crop 100x100+0+0 +repage $img_path";
d("Squaring image: $command");
$output = exec($command);
if($output == "")
echo('1');
else
{
d("ImageMagick Error: $output");
echo($output);
}
}