Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get image stream #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/PHPImageWorkshop/Core/ImageWorkshopLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,67 @@ public function write($text, $fontPath, $fontSize = 13, $color = 'ffffff', $posi

// Manage the result
// =========================================================

/**
* Return a merged resource image as a JPG raw image stream which can be saved into a file or served on the fly by
* printing the result with the proper headers:
* header('Content-type: image/png');
* header('Content-Disposition: filename="myfile.png"');
*
* @param string $backgroundColor [optional]
* @param int $quality [optional] quality is optional, and ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). Defaults to 75.
*
* @return string
*/
public function getResultAsPNG($backgroundColor = null, $quality = 75)
{
$quality = floor(($quality >= 100 ? 99:$quality) / 10);
ob_start();
imagepng($this->getResult($backgroundColor), null, $quality);
return ob_get_clean();
}

/**
* Return a merged resource image as a JPG raw image stream which can be saved into a file or served on the fly by
* printing the result with the proper headers:
* header('Content-type: image/jpeg');
* header('Content-Disposition: filename="myfile.jpg"');
*
* $backgroundColor is really usefull because the transparency of the background would be removed for a colored background, so you should choose a color like "ffffff" (white)
*
* @param string $backgroundColor [optional]
* @param int $quality [optional] quality is optional, and ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). Defaults to 75.
* @param bool $interlace [optional] enables interlace, defaults to false
*
* @return string
*/
public function getResultAsJPG($backgroundColor = null, $quality = 75, $interlace = false)
{
$result = $this->getResult($backgroundColor);
imageinterlace($result, (int)$interlace);
ob_start();
imagejpeg($result, null, $quality);
return ob_get_clean();
}

/**
* Return a merged resource image as a GIF raw image stream which can be saved into a file or served on the fly by
* printing the result with the proper headers:
* header('Content-type: image/gif');
* header('Content-Disposition: filename="myfile.gif"');
*
* $backgroundColor is really usefull because the transparency of the background would be removed for a colored background, so you should choose a color like "ffffff" (white)
*
* @param string $backgroundColor [optional]
*
* @return string
*/
public function getResultAsGIF($backgroundColor = null)
{
ob_start();
imagegif($this->getResult($backgroundColor), null);
return ob_get_clean();
}

/**
* Return a merged resource image
Expand Down