Make WordPress Core

Ticket #1703: kubrickheader.php

File kubrickheader.php, 2.0 KB (added by skeltoac, 20 years ago)

wp-content/themes/default/images/kubrickheader.php

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