-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrainbow.php
93 lines (77 loc) · 2.67 KB
/
rainbow.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
//See if they passed a image argument
if( isset($argv[1]) == FALSE ) {
die("\r\nNo picture was passed through!\r\n");
}
//Validate the argument is a valid image
if( function_exists("finfo_file") == FALSE ) {
die("\r\nFunction finfo_file needs to exist for this!\r\n");
}
//See what the MIME type is of the file...
$resFinfo = finfo_open(FILEINFO_MIME_TYPE);
switch( strtoupper(finfo_file($resFinfo, $argv[1])) ) {
case 'IMAGE/JPEG' :
case 'IMAGE/JPG' :
$resImage = imagecreatefromjpeg($argv[1]);
define("__FILE_TYPE__", "JPG");
break;
case 'IMAGE/PNG' :
$resImage = imagecreatefrompng($argv[1]);
define("__FILE_TYPE__", "PNG");
break;
case 'IMAGE/GIF' :
$resImage = imagecreatefromgif($argv[1]);
define("__FILE_TYPE__", "GIF");
break;
default :
die("\r\nInvalid file type!\r\n");
break;
}
if( is_resource($resImage) === FALSE ) {
die("\r\nSorry, something went wrong!\r\n");
}
$arrImageSize = getimagesize($argv[1]);
$resTrueColor = imagecreatetruecolor($arrImageSize[0], $arrImageSize[1]);
//Check truecolor was a success
if($resTrueColor === FALSE) {
die("\r\nSorry, something went wrong!\r\n");
}
//Now we draw the rectangles to make the rainbow <3
$intHeightOfBlock = $arrImageSize[1] / 8;
$arrColours = array(
'hot_pink' => imagecolorallocate($resImage, 255, 105, 180), //Sexuality
'red' => imagecolorallocate($resImage, 255, 0, 0), //Life
'orange' => imagecolorallocate($resImage, 255, 128, 0), //Healing
'yellow' => imagecolorallocate($resImage, 255, 255, 0), //Sunlight
'green' => imagecolorallocate($resImage, 0, 128, 0), //Nature
'turquoise' => imagecolorallocate($resImage, 51, 221, 221), //Magic/Art
'blue' => imagecolorallocate($resImage, 0, 0, 225), //Serenity/Harmony
'violet' => imagecolorallocate($resImage, 160, 0, 192) //Spirit
);
$intIteration = 0;
foreach($arrColours as $intHexColour) {
imagefilledrectangle($resTrueColor,
0,
$intHeightOfBlock * $intIteration,
$arrImageSize[0],
($intHeightOfBlock * $intIteration) + $intHeightOfBlock,
$intHexColour);
$intIteration++;
}
imagecopymerge($resImage, $resTrueColor, 0, 0, 0, 0, $arrImageSize[0], $arrImageSize[1], 30);
switch(__FILE_TYPE__) {
case 'JPG' :
imagejpeg($resImage, 'rainbow_'.$argv[1]);
break;
case 'GIF' :
imagegif($resImage, 'rainbow_'.$argv[1]);
break;
case 'PNG' :
imagepng($resImage, 'rainbow_'.$argv[1]);
break;
default :
die("\r\nUnsupported file type\r\n");
break;
}
imagedestroy($resImage);
die("\r\nImage has been rainbowfied!\r\n");