function ctools_stylizer_image_processor::new_image

Prepare a new image for being copied or worked on, preserving transparency.

2 calls to ctools_stylizer_image_processor::new_image()
ctools_stylizer_image_processor::command_new_from in includes/stylizer.inc
Create a new workspace using the properties of an existing workspace.
ctools_stylizer_image_processor::command_slice in includes/stylizer.inc
Take a slice out of the current workspace and save it as an image.

File

includes/stylizer.inc, line 590

Class

ctools_stylizer_image_processor

Code

function &new_image(&$source, $width = NULL, $height = NULL) {
    if (!isset($width)) {
        $width = imagesx($source);
    }
    if (!isset($height)) {
        $height = imagesy($source);
    }
    $target = imagecreatetruecolor($width, $height);
    imagealphablending($target, FALSE);
    imagesavealpha($target, TRUE);
    $transparency_index = imagecolortransparent($source);
    // If we have a specific transparent color
    if ($transparency_index >= 0) {
        // Get the original image's transparent color's RGB values
        $transparent_color = imagecolorsforindex($source, $transparency_index);
        // Allocate the same color in the new image resource
        $transparency_index = imagecolorallocate($target, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
        // Completely fill the background of the new image with allocated color.
        imagefill($target, 0, 0, $transparency_index);
        // Set the background color for new image to transparent
        imagecolortransparent($target, $transparency_index);
    }
    else {
        // Create a new transparent color for image
        $color = imagecolorallocatealpha($target, 0, 0, 0, 127);
        // Completely fill the background of the new image with allocated color.
        imagefill($target, 0, 0, $color);
    }
    return $target;
}