PageRenderTime 44ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/themes/default/images/header-img.php

https://github.com/localshred/dtraders
PHP | 77 lines | 59 code | 10 blank | 8 comment | 14 complexity | f7e27d81f68dc918de6c7c323f11adf1 MD5 | raw file
  1. <?php
  2. $img = 'kubrickheader.jpg';
  3. // If we don't have image processing support, redirect.
  4. if ( ! function_exists('imagecreatefromjpeg') )
  5. die(header("Location: kubrickheader.jpg"));
  6. // Assign and validate the color values
  7. $default = false;
  8. $vars = array('upper'=>array('r1', 'g1', 'b1'), 'lower'=>array('r2', 'g2', 'b2'));
  9. foreach ( $vars as $var => $subvars ) {
  10. if ( isset($_GET[$var]) ) {
  11. foreach ( $subvars as $index => $subvar ) {
  12. $length = strlen($_GET[$var]) / 3;
  13. $v = substr($_GET[$var], $index * $length, $length);
  14. if ( $length == 1 ) $v = '' . $v . $v;
  15. $$subvar = hexdec( $v );
  16. if ( $$subvar < 0 || $$subvar > 255 )
  17. $default = true;
  18. }
  19. } else {
  20. $default = true;
  21. }
  22. }
  23. if ( $default )
  24. list ( $r1, $g1, $b1, $r2, $g2, $b2 ) = array ( 105, 174, 231, 65, 128, 182 );
  25. // Create the image
  26. $im = imagecreatefromjpeg($img);
  27. // Get the background color, define the rectangle height
  28. $white = imagecolorat( $im, 15, 15 );
  29. $h = 182;
  30. // Define the boundaries of the rounded edges ( y => array ( x1, x2 ) )
  31. $corners = array(
  32. 0 => array ( 25, 734 ),
  33. 1 => array ( 23, 736 ),
  34. 2 => array ( 22, 737 ),
  35. 3 => array ( 21, 738 ),
  36. 4 => array ( 21, 738 ),
  37. 177 => array ( 21, 738 ),
  38. 178 => array ( 21, 738 ),
  39. 179 => array ( 22, 737 ),
  40. 180 => array ( 23, 736 ),
  41. 181 => array ( 25, 734 ),
  42. );
  43. // Blank out the blue thing
  44. for ( $i = 0; $i < $h; $i++ ) {
  45. $x1 = 19;
  46. $x2 = 740;
  47. imageline( $im, $x1, 18 + $i, $x2, 18 + $i, $white );
  48. }
  49. // Draw a new color thing
  50. for ( $i = 0; $i < $h; $i++ ) {
  51. $x1 = 20;
  52. $x2 = 739;
  53. $r = ( $r2 - $r1 != 0 ) ? $r1 + ( $r2 - $r1 ) * ( $i / $h ) : $r1;
  54. $g = ( $g2 - $g1 != 0 ) ? $g1 + ( $g2 - $g1 ) * ( $i / $h ) : $g1;
  55. $b = ( $b2 - $b1 != 0 ) ? $b1 + ( $b2 - $b1 ) * ( $i / $h ) : $b1;
  56. $color = imagecolorallocate( $im, $r, $g, $b );
  57. if ( array_key_exists($i, $corners) ) {
  58. imageline( $im, $x1, 18 + $i, $x2, 18 + $i, $white );
  59. list ( $x1, $x2 ) = $corners[$i];
  60. }
  61. imageline( $im, $x1, 18 + $i, $x2, 18 + $i, $color );
  62. }
  63. //die;
  64. header("Content-Type: image/jpeg");
  65. imagejpeg($im, '', 92);
  66. imagedestroy($im);
  67. ?>