本文整理汇总了PHP中imagefilter函数的典型用法代码示例。如果您正苦于以下问题:PHP imagefilter函数的具体用法?PHP imagefilter怎么用?PHP imagefilter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagefilter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*/
protected function execute(array $arguments)
{
if ($arguments['level']) {
return imagefilter($this->getToolkit()->getResource(), IMG_FILTER_BRIGHTNESS, round($arguments['level'] / 100 * 255));
}
return TRUE;
}
示例2: apply
/**
* @param Image $image
*
* @return Image
*/
public function apply($image)
{
for ($i = 0; $i < $this->amount; $i++) {
imagefilter($image->getCore(), IMG_FILTER_GAUSSIAN_BLUR);
}
return $image;
}
示例3: execute
public function execute(array $options = array())
{
if (!isset($options[IMG_FILTER_CONTRAST]) || !is_int($options[IMG_FILTER_CONTRAST])) {
throw new InvalidArgumentException('No valid contrast value was given. Expected integer.');
}
imagefilter($this->handle, IMG_FILTER_CONTRAST, $options[IMG_FILTER_CONTRAST]);
}
示例4: apply
public function apply($resource)
{
$times = 0;
while (++$times != $this->settings->strength) {
imagefilter($resource->image, IMG_FILTER_GAUSSIAN_BLUR);
}
}
示例5: resize_uploaded_file
function resize_uploaded_file($sIn, $sOut)
{
$hIn = imagecreatefromjpeg($sIn);
imagefilter($hIn, IMG_FILTER_CONTRAST, 20);
list($x, $y, $type, $attr) = getimagesize($sIn);
if ($x > $y) {
$nXNew = $y * 260 / 200;
$nYNew = $y;
$nXOffs = ($x - $nXNew) / 2;
$hCanvas = imagecreatetruecolor($nXNew, $y);
imagecopy($hCanvas, $hIn, 0, 0, $nXOffs, 0, $nXNew, $y);
} else {
$nXNew = $x;
$nYNew = $x * 200 / 260;
$nYOffs = ($y - $nYNew) / 2;
$hCanvas = imagecreatetruecolor($x, $nYNew);
imagecopy($hCanvas, $hIn, 0, 0, 0, $nYOffs, $x, $nYNew);
}
$h160x150 = imagecreatetruecolor(260, 200);
imagecopyresampled($h160x150, $hCanvas, 0, 0, 0, 0, 260, 200, $nXNew, $nYNew);
$sOutfile = preg_replace('/\\.jpg/i', '_260x200.jpg', $sOut);
imagejpeg($h160x150, $sOutfile, 100);
unlink($sIn);
return $sOutfile;
}
示例6: Render
public function Render()
{
$text = $this->GenWord();
$this->InitImage();
$this->SetText($text);
// $this->WaveImage();
$this->SetBackground();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
switch ($this->format) {
case IMG_PNG:
header("Content-type: image/png");
if ($this->blur && function_exists('imagefilter')) {
imagefilter($this->im, IMG_FILTER_GAUSSIAN_BLUR);
}
imagepng($this->im);
imagedestroy($this->im);
break;
default:
break;
}
die;
}
示例7: execute
public function execute(array $options = array())
{
if (!isset($options[IMG_FILTER_BRIGHTNESS]) || !is_int($options[IMG_FILTER_BRIGHTNESS])) {
throw new InvalidArgumentException('No valid brightness value was given. Expected integer.');
}
imagefilter($this->handle, IMG_FILTER_BRIGHTNESS, $options[IMG_FILTER_BRIGHTNESS]);
}
示例8: negative
/**
* {@inheritdoc}
*/
public function negative()
{
if (false === imagefilter($this->ressource, IMG_FILTER_NEGATE)) {
throw new RuntimeException('GD Failed to negate image');
}
return $this;
}
示例9: _blur
/**
* @return Image
*/
private function _blur()
{
for ($i = 0; $i < $this->blur->blurCount; ++$i) {
imagefilter($this->_imageStruct->image, IMG_FILTER_GAUSSIAN_BLUR);
}
return $this->_imageStruct;
}
示例10: getImage
public function getImage()
{
$ini = microtime(true);
/** Initialization */
$this->ImageAllocate();
/** Text insertion */
$text = $this->getRandomText() . ' ' . $this->getRandomText();
$fontcfg = $this->fonts[array_rand($this->fonts)];
$this->WriteText($text, $fontcfg);
JRequest::setvar('com_jobboard_humanv', $text, 'post');
$app =& JFactory::getApplication();
$app->getUserStateFromRequest('com_jobboard.humanv', 'com_jobboard_humanv', $text);
/** Transformations */
$this->WaveImage();
if ($this->blur && function_exists('imagefilter')) {
imagefilter($this->im, IMG_FILTER_GAUSSIAN_BLUR);
}
$this->ReduceImage();
if ($this->debug) {
imagestring($this->im, 1, 1, $this->height - 8, "{$text} {$fontcfg['font']} " . round((microtime(true) - $ini) * 1000) . "ms", $this->GdFgColor);
}
/** Output */
$this->WriteImage();
$this->Cleanup();
}
示例11: blur
function blur($gdImageResource, $blurFactor = 3)
{
// blurFactor has to be an integer
$blurFactor = round($blurFactor);
$originalWidth = imagesx($gdImageResource);
$originalHeight = imagesy($gdImageResource);
$smallestWidth = ceil($originalWidth * pow(0.5, $blurFactor));
$smallestHeight = ceil($originalHeight * pow(0.5, $blurFactor));
// for the first run, the previous image is the original input
$prevImage = $gdImageResource;
$prevWidth = $originalWidth;
$prevHeight = $originalHeight;
// scale way down and gradually scale back up, blurring all the way
for ($i = 0; $i < $blurFactor; $i += 1) {
// determine dimensions of next image
$nextWidth = $smallestWidth * pow(2, $i);
$nextHeight = $smallestHeight * pow(2, $i);
// resize previous image to next size
$nextImage = imagecreatetruecolor($nextWidth, $nextHeight);
imagecopyresized($nextImage, $prevImage, 0, 0, 0, 0, $nextWidth, $nextHeight, $prevWidth, $prevHeight);
// apply blur filter
imagefilter($nextImage, IMG_FILTER_GAUSSIAN_BLUR);
// now the new image becomes the previous image for the next step
$prevImage = $nextImage;
$prevWidth = $nextWidth;
$prevHeight = $nextHeight;
}
// scale back to original size and blur one more time
imagecopyresized($gdImageResource, $nextImage, 0, 0, 0, 0, $originalWidth, $originalHeight, $nextWidth, $nextHeight);
imagefilter($gdImageResource, IMG_FILTER_GAUSSIAN_BLUR);
// clean up
imagedestroy($prevImage);
// return result
return $gdImageResource;
}
示例12: CreateImage
public function CreateImage()
{
$ini = microtime(true);
/** Initialization */
$this->ImageAllocate();
/** Text insertion */
$text = $this->GetCaptchaText();
$fontcfg = $this->fonts[array_rand($this->fonts)];
$this->WriteText($text, $fontcfg);
$this->session->put($this->session_var, $text);
/** Transformations */
if (!empty($this->lineWidth)) {
$this->WriteLine();
}
$this->WaveImage();
if ($this->blur && function_exists('imagefilter')) {
imagefilter($this->im, IMG_FILTER_GAUSSIAN_BLUR);
}
$this->ReduceImage();
if ($this->debug) {
imagestring($this->im, 1, 1, $this->height - 8, "{$text} {$fontcfg['font']} " . round((microtime(true) - $ini) * 1000) . "ms", $this->GdFgColor);
}
/** Output */
$data = $this->WriteImage();
$this->Cleanup();
$headers = [];
if ($this->imageFormat == 'png') {
$headers['content-type'] = 'image/png';
} else {
$headers['content-type'] = 'image/jpeg';
}
return $this->response->make($data, 200, $headers);
}
示例13: createImage
public function createImage()
{
$ini = microtime(true);
$this->imageAllocate();
$text = $this->randCaptcha;
if (is_null($text) || empty($text)) {
$text = $this->getRandCaptcha();
}
$fontcfg = $this->fonts[array_rand($this->fonts)];
$this->writeText($text, $fontcfg);
$this->randCaptcha = $text;
if (!empty($this->lineWidth)) {
$this->WriteLine();
}
$this->waveImage();
if ($this->blur && function_exists('imagefilter')) {
imagefilter($this->im, IMG_FILTER_GAUSSIAN_BLUR);
}
$this->reduceImage();
if ($this->debug) {
imagestring($this->im, 1, 1, $this->height - 8, "{$text} {$fontcfg['font']} " . round((microtime(true) - $ini) * 500) . "ms", $this->GdFgColor);
}
$this->writeImage();
$this->cleanup();
}
示例14: getTextFromImage
function getTextFromImage($file)
{
$background = imagecreatefromjpeg('background.jpg');
$image = imagecreatefromstring($file);
$black = imagecolorallocate($image, 0, 0, 0);
$min_visible_y = $max_y = imagesy($image);
$min_visible_x = $max_x = imagesx($image);
$max_visible_x = $max_visible_y = 0;
for ($y = 0; $y < $max_y; $y++) {
for ($x = 0; $x < $max_x; $x++) {
$pixel = ImageColorAt($image, $x, $y);
$colors = imagecolorsforindex($image, $pixel);
$pixel_bg = ImageColorAt($background, $x, $y);
$colors_bg = imagecolorsforindex($background, $pixel_bg);
$range = 35;
if ($colors['red'] + $range > $colors_bg['red'] && $colors['red'] - $range < $colors_bg['red']) {
imagesetpixel($image, $x, $y, $black);
} else {
$min_visible_x = $min_visible_x > $x ? $x : $min_visible_x;
$max_visible_x = $max_visible_x < $x ? $x : $max_visible_x;
$min_visible_y = $min_visible_y > $y ? $y : $min_visible_y;
$max_visible_y = $max_visible_y < $y ? $y : $max_visible_y;
}
}
}
$image = imagecrop($image, ['x' => $min_visible_x, 'y' => $min_visible_y, 'width' => $max_visible_x, 'height' => $max_visible_y]);
imagefilter($image, IMG_FILTER_GRAYSCALE);
$tmpfname = tempnam("/tmp", "OCR");
imagepng($image, $tmpfname);
$txt = $ocr->recognize($tmpfname, ['eng'], 3);
unlink($tmpfname);
return str_replace("\n", "", $txt);
}
示例15: applyFilter
function applyFilter(Canvas $canvas)
{
$himage = $canvas->getImage();
if (function_exists('imagefilter')) {
// If gd is bundled this will work
imagefilter($himage, IMG_FILTER_GRAYSCALE);
} else {
// If not we need to do some enumeration
$total = imagecolorstotal($himage);
if ($total > 0) {
// This works for indexed images but not for truecolor
for ($i = 0; $i < $total; $i++) {
$index = imagecolorsforindex($himage, $i);
$avg = ($index["red"] + $index["green"] + $index["blue"]) / 3;
$red = $avg;
$green = $avg;
$blue = $avg;
imagecolorset($himage, $i, $red, $green, $blue);
}
} else {
// For truecolor we need to enum it all
for ($x = 0; $x < imagesx($himage); $x++) {
for ($y = 0; $y < imagesy($himage); $y++) {
$index = imagecolorat($himage, $x, $y);
$avg = (($index & 0xff) + ($index >> 8 & 0xff) + ($index >> 16 & 0xff)) / 3;
imagesetpixel($himage, $x, $y, $avg | $avg << 8 | $avg << 16);
}
}
}
}
}