PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/FuChi/ushahidi/application/controllers/swatch.php

https://github.com/dannyrealfox/Fu-Chi--Future-Chinatown
PHP | 111 lines | 76 code | 17 blank | 18 comment | 13 complexity | 89b4a0e80e56bb44d52570e72f892891 MD5 | raw file
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2. /**
  3. * Swatch Controller
  4. *
  5. * PHP version 5
  6. * LICENSE: This source file is subject to LGPL license
  7. * that is available through the world-wide-web at the following URI:
  8. * http://www.gnu.org/copyleft/lesser.html
  9. * @author Ushahidi Team <team@ushahidi.com>
  10. * @package Ushahidi - http://source.ushahididev.com
  11. * @module Swatch Controller
  12. * @copyright Ushahidi - http://www.ushahidi.com
  13. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
  14. */
  15. class Swatch_Controller extends Controller
  16. {
  17. function index()
  18. {
  19. // Image Color
  20. if (!isset($_GET['c'])) {
  21. $main_color = "990000";
  22. }
  23. else
  24. {
  25. $main_color = $_GET['c'];
  26. }
  27. // Image Width
  28. if (!isset($_GET['w']) || !is_numeric($_GET['w'])) {
  29. $width = "16";
  30. }
  31. else
  32. {
  33. $width = $_GET['w'];
  34. }
  35. // Image Height
  36. if (!isset($_GET['h']) || !is_numeric($_GET['h'])) {
  37. $height = "16";
  38. }
  39. else
  40. {
  41. $height = $_GET['h'];
  42. }
  43. // Image Border Color
  44. if (!isset($_GET['b'])) {
  45. $brdr_color = "990000";
  46. }
  47. else
  48. {
  49. $brdr_color = $_GET['b'];
  50. }
  51. // Image Type (Circle or Rectangle?)
  52. if (!isset($_GET['t']) || ($_GET['t'] != "rec" && $_GET['t'] != "cir") ) {
  53. $image_type = "rec";
  54. }
  55. else
  56. {
  57. $image_type = $_GET['t'];
  58. }
  59. $mc_red = hexdec(substr($main_color, 0, 2));
  60. $mc_green = hexdec(substr($main_color, 2, 2));
  61. $mc_blue = hexdec(substr($main_color, 4, 2));
  62. $bc_red = hexdec(substr($brdr_color, 0, 2));
  63. $bc_green = hexdec(substr($brdr_color, 2, 2));
  64. $bc_blue = hexdec(substr($brdr_color, 4, 2));
  65. if ($image_type == 'rec')
  66. {
  67. $image = imagecreate( $width, $height );
  68. $main_color = imagecolorallocate( $image, $mc_red, $mc_green, $mc_blue );
  69. $brdr_color = imagecolorallocate( $image, $bc_red, $bc_green, $bc_blue );
  70. imagefill( $image, 0, 0, $brdr_color);
  71. imagefilledrectangle( $image, 1, 1, ($width-2), ($height-2), $main_color);
  72. }
  73. else
  74. { // Use imagecolorallocatealpha to set transparency level
  75. $a = $width;
  76. $b = $a*4;
  77. $c = $b/2;
  78. $d = $b;
  79. $e = $d-(2*8);
  80. $image = imagecreate( $a, $a );
  81. $image2 = imagecreate( ($b), ($b) );
  82. $main_color = imagecolorallocatealpha( $image2, $mc_red, $mc_green, $mc_blue, 20 );
  83. $brdr_color = imagecolorallocatealpha( $image2, $bc_red, $bc_green, $bc_blue, 0 );
  84. $bkg_color = imagecolorallocatealpha($image2, 0, 0, 0, 127);
  85. imagefill($image2, 0, 0, $bkg_color);
  86. imagefilledellipse( $image2, $c, $c, $d, $d, $brdr_color);
  87. imagefilledellipse( $image2, $c, $c, $e, $e, $main_color);
  88. imagecopyresampled($image,$image2,0,0,0,0,$a,$a,$b,$b);
  89. }
  90. header("Content-type: image/png");
  91. imagepng($image);
  92. imagedestroy($image);
  93. }
  94. }