/[drupal]/contributions/modules/color_soc08/color.image.inc
ViewVC logotype

Contents of /contributions/modules/color_soc08/color.image.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Fri Aug 22 10:21:56 2008 UTC (15 months, 1 week ago) by skiquel
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +31 -17 lines
File MIME type: text/x-php
head commit
1 <?php
2 // $Id: color.image.inc,v 1.4.2.3 2008/08/20 16:45:41 skiquel Exp $
3 /**
4 * @file
5 * Provides image manipulation functions
6 */
7
8 /**
9 * Generate images
10 *
11 * @param $theme
12 * String with theme name
13 * @param $info
14 * Array with theme info
15 * @param $paths
16 * Array containing file paths to files
17 * @param $palette
18 * Array of hex values. i.e. array('#ffffff', '#000000')
19 * @return
20 * Array of generated image file paths
21 */
22 function _color_render_images($theme, &$info, &$paths, $palette) {
23 module_load_include('inc', 'color', 'color.algorithms');
24 module_load_include('inc', 'color', 'color.database');
25
26 $info = color_get_theme_info($theme);
27
28 foreach ($info['img'] as $img) {
29 // Prepare template image.
30 $source = $paths['source'] .'/'. $img['file'];
31 $source = imagecreatefrompng($source);
32
33 imagealphablending($source, FALSE);
34 imagesavealpha($source, TRUE);
35
36 $width = imagesx($source);
37 $height = imagesy($source);
38
39 // Prepare target buffer.
40 $target = imagecreatetruecolor($width, $height);
41 imagealphablending($target, TRUE);
42
43 // Fill regions of solid color.
44 if (isset($img['fill']) && count($img['fill']) > 0) {
45 foreach ($img['fill'] as $fill) {
46 imagefilledrectangle($target, $fill[0], $fill[1], $fill[0] + $fill[2], $fill[1] + $fill[3], _color_gd($target, $palette[$fill[4]]));
47 }
48 }
49
50 // Render gradient.
51 if (isset($img['gradient']) && count($img['gradient']) > 0) {
52 foreach ($img['gradient'] as $gradient) {
53 for ($y = 0; $y < $gradient[3]; ++$y) {
54 $color = _color_blend($target, $palette[$gradient[4]], $palette[$gradient[5]], $y / ($gradient[3] - 1));
55 imagefilledrectangle($target, $gradient[0], $gradient[1] + $y, $gradient[0] + $gradient[2], $gradient[1] + $y + 1, $color);
56 }
57 }
58 }
59 // Blend over template.
60 imagecopy($target, $source, 0, 0, 0, 0, $width, $height);
61
62 // Clean up template image.
63 imagedestroy($source);
64
65 // Cut out slices.
66 foreach ($img['slices'] as $file => $coord) {
67 list($x, $y, $width, $height) = $coord;
68 $base = basename($file);
69 $image = $paths['target'] . $base;
70
71 // Cut out slice.
72 if ($file == 'screenshot.png') {
73 $slice = imagecreatetruecolor(150, 90);
74 imagecopyresampled($slice, $target, 0, 0, $x, $y, 150, 90, $width, $height);
75 variable_set('color_'. $theme .'_screenshot', $image);
76 }
77 else {
78 $slice = imagecreatetruecolor($width, $height);
79
80 imagealphablending($target, TRUE);
81 imagecopy($slice, $target, 0, 0, $x, $y, $width, $height);
82 }
83
84 // Save image.
85 if (isset($img['transparent_color']) && !empty($img['transparent_color'])) {
86 imagecolortransparent($slice, $black);
87 }
88 imagepng($slice, $image);
89 imagedestroy($slice);
90 $paths['files'][] = $image;
91
92 // Set standard file permissions for webserver-generated files
93 @chmod(realpath($image), 0664);
94
95 // Build before/after map of image paths.
96 $paths['map'][$file] = $base;
97 }
98
99 // Clean up target buffer.
100 imagedestroy($target);
101 }
102
103 return $paths;
104 }

  ViewVC Help
Powered by ViewVC 1.1.2