You are here

function ctools_stylizer_image_processor::command_slice in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 includes/stylizer.inc \ctools_stylizer_image_processor::command_slice()

Take a slice out of the current workspace and save it as an image.

File

includes/stylizer.inc, line 555
Create customized CSS and images from palettes created by user input.

Class

ctools_stylizer_image_processor

Code

function command_slice($file, $x = NULL, $y = NULL, $width = NULL, $height = NULL) {
  if (!isset($x)) {
    $x = $y = 0;
    $width = imagesx($this->workspace);
    $height = imagesy($this->workspace);
  }
  $this
    ->log("Slice: {$file} ({$x}, {$y}, {$width}, {$height})");
  $base = basename($file);
  $image = $this->path . '/' . $base;
  $slice = $this
    ->new_image($this->workspace, $width, $height);
  imagecopy($slice, $this->workspace, 0, 0, $x, $y, $width, $height);

  // Make sure alphas are saved:
  imagealphablending($slice, FALSE);
  imagesavealpha($slice, TRUE);

  // Save image.
  $temp_name = drupal_tempnam('temporary://', 'file');
  imagepng($slice, drupal_realpath($temp_name));
  file_unmanaged_move($temp_name, $image);
  imagedestroy($slice);

  // Set standard file permissions for webserver-generated files
  @chmod(realpath($image), 0664);
  $this->paths[$file] = $image;
}