~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to sites/all/themes/ubuntu-loco/borders/gradient.php

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id$
 
3
header("Content-type: image/png");
 
4
 
 
5
/* 
 
6
 * @file Background Gradient Image generator
 
7
 *
 
8
 * This file create a background gradient image using the gd library. It will return
 
9
 * the image directly and save it on the server for the next time. It will not
 
10
 * generate the same image twice.
 
11
 *
 
12
 * I used small portions of code from two web sites:
 
13
 * @see http://www.hawkee.com/snippet/5022/
 
14
 * @see http://ca.php.net/imagecolorresolve
 
15
 *
 
16
 * @author David Giard (swe3tdave)
 
17
 *
 
18
 * @param start Starting Color
 
19
 * @param end End Color
 
20
 *
 
21
 * @return Generated or Cached Image
 
22
 *
 
23
 * @note
 
24
 * Use it as you would a normal image, like this:
 
25
 * <img src="gradient.php?start=796646&end=D3CAAA">
 
26
 * Or inside a css file:
 
27
 * background-image: url(gradient.php?start=796646&end=D3CAAA);
 
28
 */
 
29
 
 
30
$height = 520;
 
31
$width = 1;
 
32
$default_background = "background.png";
 
33
$default_start_color = '796646';
 
34
$default_end_color = 'D3CAAA';
 
35
$default_image_path = ''; // Default to script directory
 
36
 
 
37
/*
 
38
 * Changing those will change how the gradient curve is generated. So you can try
 
39
 * changing them and see what appends. Here are the default setting in case you
 
40
 * want to change back :
 
41
 * 
 
42
 * $gradient_start = 65;
 
43
 * $gradient_curve = 1.1;
 
44
 * $gradient_sum = 800 / $gradient_curve;
 
45
 */
 
46
$gradient_start = 65;
 
47
$gradient_curve = 1.1;
 
48
$gradient_sum = 800 / $gradient_curve;
 
49
 
 
50
/**************************************************************************************
 
51
 * You shoudn't modify anything behond this point, unless you know what you're doing. *
 
52
 **************************************************************************************/
 
53
 
 
54
$start = $default_start_color;
 
55
$end = $default_end_color;
 
56
if ($_GET["start"]) {
 
57
  $start = $_GET["start"];
 
58
}
 
59
if ($_GET["end"]) {
 
60
  $end = $_GET["end"];
 
61
}
 
62
 
 
63
function _myexactcolor($png, $r, $g, $b) {
 
64
  $mycolor = imagecolorexact($png, $r, $g, $b);
 
65
  if ($mycolor == -1){
 
66
    $mycolor = imagecolorallocate($png, $r, $g, $b);
 
67
  }
 
68
  if ($mycolor == -1){
 
69
    $mycolor = imagecolorresolve($png, $r, $g, $b);
 
70
    #error_log("Damn!  STILL couldn't allocate the color!", 0);
 
71
  }
 
72
  return $mycolor;
 
73
}
 
74
 
 
75
function _createnewpng() {
 
76
 global $start, $end, $width, $height, $gradient_curve, $gradient_start, $gradient_sum, $default_image_path;
 
77
 
 
78
 if (!file_exists($default_image_path . $start . "-" . $end . ".png")) {
 
79
  $start_r = hexdec(substr($start, 0, 2));
 
80
  $start_g = hexdec(substr($start, 2, 2));
 
81
  $start_b = hexdec(substr($start, 4, 2));
 
82
  $end_r = hexdec(substr($end, 0, 2));
 
83
  $end_g = hexdec(substr($end, 2, 2));
 
84
  $end_b = hexdec(substr($end, 4, 2));
 
85
  $image = imagecreate($width, $height);
 
86
 
 
87
  $gradient_curve = $gradient_curve + ($start_r*(0.5/121));
 
88
 
 
89
  for($i=0;$i<250;$i++) {
 
90
     $colorset[$i] = _myexactcolor($image, $start_r + ($i*(($end_r-$start_r)/250)), $start_g + ($i*(($end_g-$start_g)/250)), $start_b + ($i*(($end_b-$start_b)/250)));
 
91
  }
 
92
  for($y=0;$y<$height;$y++) {
 
93
    for($x=0;$x<$width;$x++) {
 
94
 
 
95
      if ($y<=$gradient_start) {
 
96
        imagesetpixel ($image, $x, $y, $colorset[0] );
 
97
      }
 
98
      else {
 
99
        imagesetpixel ($image, $x, $y, $colorset[(int)(((pow($y - $gradient_start, ($gradient_sum / ($y- $gradient_start))) * 250 * pow($height - $gradient_start, 0 - ($gradient_sum / ($y- $gradient_start)))) + (pow($y - $gradient_start, $gradient_curve)* 250 *pow($height - $gradient_start, 0-$gradient_curve)))/2)] );
 
100
      }
 
101
    }
 
102
  }
 
103
 
 
104
  imagepng($image,$default_image_path . $start . "-" . $end . ".png");
 
105
  imagepng($image);
 
106
  imagedestroy($image);
 
107
 }
 
108
 else {
 
109
 $h = fopen($default_image_path . $start . "-" . $end . ".png", "r");
 
110
 fpassthru($h);
 
111
 fclose($h);
 
112
 }
 
113
}
 
114
 
 
115
 
 
116
if ($start != $default_start_color || $end != $default_end_color) {
 
117
  _createnewpng();
 
118
}
 
119
else {
 
120
  if (file_exists($default_image_path . $default_background)) {
 
121
     $h = fopen($default_image_path . $default_background, "r");
 
122
     fpassthru($h);
 
123
     fclose($h);
 
124
  }
 
125
  else {
 
126
    _createnewpng();
 
127
  }
 
128
}
 
129
 
 
130
?>
 
 
b'\\ No newline at end of file'