Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(array $arguments)
 {
     if ($arguments['level']) {
         return imagefilter($this->getToolkit()->getResource(), IMG_FILTER_BRIGHTNESS, round($arguments['level'] / 100 * 255));
     }
     return TRUE;
 }
Example #2
0
 /**
  * @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;
 }
Example #3
0
 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]);
 }
Example #4
0
 public function apply($resource)
 {
     $times = 0;
     while (++$times != $this->settings->strength) {
         imagefilter($resource->image, IMG_FILTER_GAUSSIAN_BLUR);
     }
 }
Example #5
0
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;
}
Example #6
0
 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;
 }
Example #7
0
 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]);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function negative()
 {
     if (false === imagefilter($this->ressource, IMG_FILTER_NEGATE)) {
         throw new RuntimeException('GD Failed to negate image');
     }
     return $this;
 }
Example #9
0
 /**
  * @return Image
  */
 private function _blur()
 {
     for ($i = 0; $i < $this->blur->blurCount; ++$i) {
         imagefilter($this->_imageStruct->image, IMG_FILTER_GAUSSIAN_BLUR);
     }
     return $this->_imageStruct;
 }
Example #10
0
 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();
 }
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;
}
Example #12
0
 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);
 }
Example #13
0
 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();
 }
Example #14
0
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);
}
Example #15
0
 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);
                 }
             }
         }
     }
 }
Example #16
0
 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);
     $_SESSION[$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 */
     $this->WriteImage();
     $this->Cleanup();
 }
Example #17
0
 public function apply($resource)
 {
     if ($this->settings->xoffset < 0) {
         $xextra = 0 - $this->settings->xoffset;
     } else {
         $xextra = $this->settings->xoffset;
     }
     if ($this->settings->yoffset < 0) {
         $yextra = 0 - $this->settings->yoffset;
     } else {
         $yextra = $this->settings->yoffset;
     }
     $rextra = ceil($this->settings->radius / 2);
     $image = (object) array('width' => imagesx($resource->image) + $rextra + $xextra, 'height' => imagesy($resource->image) + $rextra + $yextra);
     $source = (object) array('top' => $this->settings->yoffset < 0 ? $yextra + $rextra : 0, 'left' => $this->settings->xoffset < 0 ? $xextra + $rextra : 0, 'width' => imagesx($resource->image), 'height' => imagesy($resource->image));
     $shadow = (object) array('top' => $this->settings->yoffset < 0 ? $rextra : $yextra, 'left' => $this->settings->xoffset < 0 ? $rextra : $xextra, 'width' => imagesx($resource->image) - 1, 'height' => imagesy($resource->image) - 1);
     //var_dump($shadow);
     //exit;
     $new = imagecreatetruecolor($image->width, $image->height);
     $colour = new Colour($this->settings->bg);
     $bg = $colour->allocate($new);
     imagefill($new, 0, 0, $bg);
     $colour = new Colour($this->settings->fg);
     $fg = $colour->allocate($new);
     imagefilledrectangle($new, $shadow->left, $shadow->top, $shadow->left + $shadow->width, $shadow->top + $shadow->height, $fg);
     if ($this->settings->radius > 0) {
         $times = 0;
         while (++$times != $this->settings->radius) {
             imagefilter($new, IMG_FILTER_GAUSSIAN_BLUR);
         }
     }
     imagecopyresampled($new, $resource->image, $source->left, $source->top, 0, 0, $source->width, $source->height, $source->width, $source->height);
     $resource->image = $new;
 }
Example #18
0
 public function execute(array $options = array())
 {
     if (!isset($options[IMG_FILTER_SMOOTH]) || !is_int($options[IMG_FILTER_SMOOTH])) {
         throw new InvalidArgumentException('No valid smoothing value was given.  Expected integer.');
     }
     imagefilter($this->handle, IMG_FILTER_SMOOTH, $options[IMG_FILTER_SMOOTH]);
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 public function colorize(Color $color)
 {
     if (false === imagefilter($this->resource, IMG_FILTER_COLORIZE, $color->getRed(), $color->getGreen(), $color->getBlue())) {
         throw new RuntimeException('Failed to colorize the image');
     }
     return $this;
 }
 public function run($file)
 {
     $res = $this->open_image($file);
     if ($res != TRUE) {
         return FALSE;
     }
     $this->image_progressive = isset($this->settings['field_settings']['progressive_jpeg']) === TRUE && $this->settings['field_settings']['progressive_jpeg'] == 'yes' ? TRUE : FALSE;
     if (function_exists('imagefilter') === TRUE) {
         @imagefilter($this->EE->channel_images->image, IMG_FILTER_GRAYSCALE);
     } else {
         $img_width = imageSX($this->EE->channel_images->image);
         $img_height = imageSY($this->EE->channel_images->image);
         // convert to grayscale
         $palette = array();
         for ($c = 0; $c < 256; $c++) {
             $palette[$c] = imagecolorallocate($this->EE->channel_images->image, $c, $c, $c);
         }
         for ($y = 0; $y < $img_height; $y++) {
             for ($x = 0; $x < $img_width; $x++) {
                 $rgb = imagecolorat($this->EE->channel_images->image, $x, $y);
                 $r = $rgb >> 16 & 0xff;
                 $g = $rgb >> 8 & 0xff;
                 $b = $rgb & 0xff;
                 $gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
                 imagesetpixel($this->EE->channel_images->image, $x, $y, $palette[$gs]);
             }
         }
     }
     $this->save_image($file);
     return TRUE;
 }
 /**
  * blur the image
  */
 public function blur($intensity)
 {
     $image = $this->owner->getImageResource();
     switch ($intensity) {
         case 'light':
             for ($x = 1; $x <= 10; $x++) {
                 imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
             }
             break;
         case 'strong':
             for ($x = 1; $x <= 40; $x++) {
                 imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
             }
             break;
         case 'normal':
         default:
             for ($x = 1; $x <= 25; $x++) {
                 imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
             }
             break;
     }
     $output = clone $this->owner;
     $output->setImageResource($image);
     return $output;
 }
Example #22
0
 /**
  * Turns an image into a greyscale version
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     foreach ($image as $frame) {
         imagefilter($frame->getCore(), IMG_FILTER_GRAYSCALE);
     }
     return true;
 }
Example #23
0
 public function apply($image)
 {
     // subtract the opposite color from the image
     if (!imagefilter($image, IMG_FILTER_COLORIZE, $this->red, $this->green, $this->blue, $this->alpha)) {
         throw new FilterException('Fail to apply multiply filter.');
     }
 }
Example #24
0
 public static function ImageColorize(&$image, $hex)
 {
     $rgb = ColorUtils::hex2rgb($hex);
     if (function_exists('imagefilter')) {
         imagefilter($image, IMG_FILTER_COLORIZE, $rgb['r'], $rgb['g'], $rgb['b']);
     }
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 protected function execute(array $arguments)
 {
     if ($arguments['level']) {
         return imagefilter($this->getToolkit()->getResource(), IMG_FILTER_CONTRAST, $arguments['level'] * -1);
     }
     return TRUE;
 }
Example #26
0
 public function execute()
 {
     $options = [];
     $options['gaussian'] = IMG_FILTER_GAUSSIAN_BLUR;
     $options['selective'] = IMG_FILTER_SELECTIVE_BLUR;
     $this->media->asImage();
     $gdimage = $this->media->getImage();
     $this->params['repeats'] = (int) $this->params['repeats'];
     if ($this->params['repeats'] < 0) {
         return;
     }
     if (!in_array($this->params['type'], $this->options)) {
         $this->params['type'] = '';
     }
     if (!in_array($this->params['smoothit'], $this->options_smoothit)) {
         $this->params['smoothit'] = '';
     }
     for ($i = 0; $i < $this->params['repeats']; ++$i) {
         if ($this->params['smoothit'] != '') {
             imagefilter($gdimage, IMG_FILTER_SMOOTH, $this->params['smoothit']);
         }
         if ($this->params['type'] != '') {
             imagefilter($gdimage, $options[$this->params['type']]);
         }
     }
 }
Example #27
0
 /**
  * {@inheritdoc}
  */
 public function grayscale()
 {
     if (false === imagefilter($this->resource, IMG_FILTER_GRAYSCALE)) {
         throw new RuntimeException('Failed to grayscale the image');
     }
     return $this;
 }
Example #28
0
 /**
  * {@inheritdoc}
  */
 public function apply(Imanee $imanee, array $options = [])
 {
     /** @var resource $resource */
     $resource = $imanee->getResource()->getResource();
     imagefilter($resource, IMG_FILTER_GRAYSCALE);
     imagefilter($resource, IMG_FILTER_COLORIZE, 100, 50, 0);
 }
Example #29
0
 /**
  * Applies blur effect on image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $amount = $this->argument(0)->between(0, 100)->value(1);
     for ($i = 0; $i < intval($amount); $i++) {
         imagefilter($image->getCore(), IMG_FILTER_GAUSSIAN_BLUR);
     }
     return true;
 }
Example #30
0
 /**
  * {@inheritdoc}
  */
 public function apply(Imanee $imanee, array $options = [])
 {
     /** @var resource $resource */
     $resource = $imanee->getResource()->getResource();
     $options = array_merge(['brightness' => 50, 'contrast' => -10], $options);
     imagefilter($resource, IMG_FILTER_BRIGHTNESS, $options['brightness']);
     imagefilter($resource, IMG_FILTER_CONTRAST, $options['saturation']);
 }