Same name and namespace in other branches
  1. 5.x modules/color/color.module \_color_render_images()
  2. 7.x modules/color/color.module \_color_render_images()
  3. 8.9.x core/modules/color/color.module \_color_render_images()
  4. 9 core/modules/color/color.module \_color_render_images()

Render images that match a given palette.

1 call to _color_render_images()
color_scheme_form_submit in modules/color/color.module
Submit handler for color change form.

File

modules/color/color.module, line 467

Code

function _color_render_images($theme, &$info, &$paths, $palette) {

  // Prepare template image.
  $source = $paths['source'] . '/' . $info['base_image'];
  $source = imagecreatefrompng($source);
  $width = imagesx($source);
  $height = imagesy($source);

  // Prepare target buffer.
  $target = imagecreatetruecolor($width, $height);
  imagealphablending($target, true);

  // Fill regions of solid color.
  foreach ($info['fill'] as $color => $fill) {
    imagefilledrectangle($target, $fill[0], $fill[1], $fill[0] + $fill[2], $fill[1] + $fill[3], _color_gd($target, $palette[$color]));
  }

  // Render gradient.
  for ($y = 0; $y < $info['gradient'][3]; ++$y) {
    $color = _color_blend($target, $palette['top'], $palette['bottom'], $y / ($info['gradient'][3] - 1));
    imagefilledrectangle($target, $info['gradient'][0], $info['gradient'][1] + $y, $info['gradient'][0] + $info['gradient'][2], $info['gradient'][1] + $y + 1, $color);
  }

  // Blend over template.
  imagecopy($target, $source, 0, 0, 0, 0, $width, $height);

  // Clean up template image.
  imagedestroy($source);

  // Cut out slices.
  foreach ($info['slices'] as $file => $coord) {
    list($x, $y, $width, $height) = $coord;
    $base = basename($file);
    $image = $paths['target'] . $base;

    // Cut out slice.
    if ($file == 'screenshot.png') {
      $slice = imagecreatetruecolor(150, 90);
      imagecopyresampled($slice, $target, 0, 0, $x, $y, 150, 90, $width, $height);
      variable_set('color_' . $theme . '_screenshot', $image);
    }
    else {
      $slice = imagecreatetruecolor($width, $height);
      imagecopy($slice, $target, 0, 0, $x, $y, $width, $height);
    }

    // Save image.
    imagepng($slice, $image);
    imagedestroy($slice);
    $paths['files'][] = $image;

    // Set standard file permissions for webserver-generated files
    @chmod(realpath($image), 0664);

    // Build before/after map of image paths.
    $paths['map'][$file] = $base;
  }

  // Clean up target buffer.
  imagedestroy($target);
}