private function _renderToImageData(&$canvas) {
        ob_start();

        switch ($this->_params['type']) {
        case IMAGETYPE_GIF:
            imagegif($canvas);
            break;
        case IMAGETYPE_JPEG:
            imagejpeg($canvas, null, $this->_params['quality']);
            break;
        case IMAGETYPE_PNG:
            // Calculate PNG quality, because it runs from 0 (uncompressed) to 9,
            // instead of 0 - 100.
            $pngQuality = ($this->_params['quality'] - 100) / 11.111111;
            $pngQuality = round(abs($pngQuality));
            imagepng($canvas, null, $pngQuality, null);
            break;
        default:
            throw new Exception('Sorry, this image type is not supported');
        }

        $imgData = ob_get_contents();
        ob_end_clean();
        return $imgData;
    }