Include watermark in thumbnail.

@param type|null $path Path to watermark

@return this
549688
public function watermark($path = null)
    {
        if (is_null($path)) {
            $this->watermarkPath(config('images.watermark_path'));
        }
        $this->watermarkPath($path);
        $this->todo('watermark');

        return $this;
    }
1027150
public function remove_path($path, $type = null)
	{
		is_null($type) and $type = $this->_path_folders;

		if( is_array($type))
		{
			foreach ($type as $key => $folder)
			{
				is_numeric($key) and $key = $folder;
				$folder = $this->_unify_path($path).ltrim($this->_unify_path($folder),DS);
				if (($found = array_search($folder, $this->_asset_paths[$key])) !== false)
				{
					unset($this->_asset_paths[$key][$found]);
				}
			}
		}
		else
		{
			$path = $this->_unify_path($path);
			if (($key = array_search($path, $this->_asset_paths[$type])) !== false)
			{
				unset($this->_asset_paths[$type][$key]);
			}
		}

		return $this;
	}
501780
public function setPath($path)
    {
        if(empty($path)) {
            $this->_path = '/';
        } else {
            $this->_path = $path;
        }

        return $this;
    }
350896
public function watermark(string $filePath)
    {
        if (! file_exists($filePath)) {
            throw new FileNotFoundException($filePath);
        }

        $this->addManipulation('watermark', $filePath);

        return $this;
    }
866165
public function addAttachment($path, $type, $title = '')
    {
        array_push($this->attachments, array(
          'path' => $path,
          'type' => $type,
          'title' => $title,
        ));

        return $this;
    }
371287
public function loadFrom($path)
    {
        // Avoid repeat load of broken images
        $hash = sha1($path);
        if ($this->hasFailed($hash, null)) {
            return $this;
        }

        // Handle resource
        $error = self::FAILED_UNKNOWN;
        try {
            $this->setImageResource($this->getImageManager()->make($path));
            $this->markSuccess($hash, null);
            $error = null;
        } catch (NotReadableException $ex) {
            // Handle unsupported image encoding on load (will be marked as failed)
            // Unsupported exceptions are handled without being raised as exceptions
            $error = self::FAILED_INVALID;
        } finally {
            if ($error) {
                $this->markFailed($hash, null, $error);
            }
        }

        return $this;
    }
14754
protected function fromFileType($path)
    {
        switch( Filesystem::getExtension($path) )
        {
            case 'png' : return imagecreatefrompng($path);
            case 'gif' : return imagecreatefromgif($path);
            case 'jpg' :
            case 'jpeg':
            default    : return imagecreatefromjpeg($path);
        }
    }
254223
public function thumb($path)
    {
        try{
            $cacheManager = $this->container->get('liip_imagine.cache.manager');
            $filter = FileManager::FILTER_NAME;
            return new \Twig_Markup(
                $cacheManager->getBrowserPath($path, $filter, array()),
                'utf8'
            );
        } catch(\Exception $e){
            return $path;
        }

    }
139012
public function save($path, $type = null)
    {
        #imagepng() - Output a PNG image to either the browser or a file
        #imagegif() - Output image to browser or file
        #imagewbmp() - Output image to browser or file
        #imagejpeg() - Output image to browser or file
        
        if (!$type) {
            $type = $this->type;
        }

        switch ($type) {
            case 'gif':
                imagegif($this->resource, $path);
                break;
            case 'png':
                $quality = (100 - $this->quality) / 10;

                if ($quality > 9) {
                    $quality = 9;
                }

                imagepng($this->resource, $path, $quality);
                break;
            case 'bmp':
            case 'wbmp':
                imagewbmp($this->resource, $path, $this->quality);
                break;
            case 'jpg':
            case 'jpeg':
            case 'pjpeg':
            default:
                imagejpeg($this->resource, $path, $this->quality);
                break;

        }

        return $this;
    }
469928
public function uploadImage(string $path, string $type = 'icon')
    {
        if (!file_exists($path) || !is_readable($path)) {
            throw new InvalidArgumentException(sprintf('File does not exist, or the file is unreadable: "%s"', $path));
        }

        return $this->httpUpload('shakearound/material/add', ['media' => $path], [], ['type' => strtolower($type)]);
    }
730761
public function enableFilemanager($path = DIR_PUBLIC_URL)
    {
        $this->setWidget(FileManager::getInstance()->setPath($path));

        return $this;
    }
213852
protected function _manipulateImage(ImageWithImagineInterface $image, ImagePathInterface $path)
    {
        if (!$image->getImagine()) {
            $image->setImagine($this->getImagine(), $this->getImagineOptions());
        }
        
        $reduce = $this->getOption('reduce', static::REDUCE_NONE);
        $anchor = $this->getOption('anchor', static::ANCHOR_CENTER | static::ANCHOR_MIDDLE);
        $repeat = $this->getOption('repeat', static::REPEAT_NONE);
        
        $iImage = $image->getImagineImage();
        
        $watermark = $this->getWatermarkImagineImage($iImage);
        
        if ($iImage->getSize()->getWidth() < $watermark->getSize()->getWidth()
            || $iImage->getSize()->getHeight() < $watermark->getSize()->getHeight()) {
            // watermark is bigger than image
            // we need to reduce/crop
            
            $width = min($iImage->getSize()->getWidth(), $watermark->getSize()->getWidth());
            $height = min($iImage->getSize()->getHeight(), $watermark->getSize()->getHeight());

            if ($this->isBit($reduce, static::REDUCE_INSET)) {
                $watermark = $watermark->thumbnail($iImage->getSize(), \Imagine\Image\ImageInterface::THUMBNAIL_INSET);
            } elseif ($this->isBit($reduce, static::REDUCE_OUTBOUND)) {
                $watermark = $watermark->thumbnail($iImage->getSize(), \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND);
            } else {
                // we crop the watermark
                
                if ($this->isBit($anchor, static::ANCHOR_LEFT)) {
                    $x = 0;
                } elseif ($this->isBit($anchor, static::ANCHOR_RIGHT)) {
                    $x = $watermark->getSize()->getWidth() - $width;
                } else /*if ($this->isBit($anchor, static::ANCHOR_CENTER))*/ {
                    $x = intval(round(($watermark->getSize()->getWidth() - $width) / 2));
                } 
                
                if ($this->isBit($anchor, static::ANCHOR_TOP)) {
                    $y = 0;
                } elseif ($this->isBit($anchor, static::ANCHOR_BOTTOM)) {
                    $y = $watermark->getSize()->getHeight() - $height;
                } else /*if ($this->isBit($anchor, static::ANCHOR_MIDDLE))*/ {
                    $y = intval(round(($watermark->getSize()->getHeight() - $height) / 2));
                } 
                $watermark = $watermark->copy()->crop(new Point($x, $y), new Box($width, $height));
            }
        }

        // from here the watermark is always smaller than the image
        
        $repeatX = $iImage->getSize()->getWidth() > $watermark->getSize()->getWidth() && $this->isBit($repeat, static::REPEAT_X);
        $repeatY = $iImage->getSize()->getHeight() > $watermark->getSize()->getHeight() && $this->isBit($repeat, static::REPEAT_Y);
        
        $cols = 1;
        if ($repeatX) {
            $cols = intval(floor($iImage->getSize()->getWidth() / $watermark->getSize()->getWidth()));
        }
        $innerWatermarkGridWidth = $watermark->getSize()->getWidth() * $cols;
        
        $rows = 1;
        if ($repeatY) {
            $rows = intval(floor($iImage->getSize()->getHeight() / $watermark->getSize()->getHeight()));
        }
        $innerWatermarkGridHeight = $watermark->getSize()->getHeight() * $rows;
        
        // first complete watermark start
        if ($this->isBit($anchor, static::ANCHOR_LEFT)) {
            $deltaX = 0;
        } elseif ($this->isBit($anchor, static::ANCHOR_RIGHT)) {
            $deltaX = $iImage->getSize()->getWidth() - $innerWatermarkGridWidth;
        } else /*if ($this->isBit($anchor, static::ANCHOR_CENTER))*/ {
            $deltaX = intval(round(($iImage->getSize()->getWidth() - $innerWatermarkGridWidth) / 2));
        }
        
        if ($this->isBit($anchor, static::ANCHOR_TOP)) {
            $deltaY = 0;
        } elseif ($this->isBit($anchor, static::ANCHOR_BOTTOM)) {
            $deltaY = $iImage->getSize()->getHeight() - $innerWatermarkGridHeight;
        } else /*if ($this->isBit($anchor, static::ANCHOR_MIDDLE))*/ {
            $deltaY = intval(round(($iImage->getSize()->getHeight() - $innerWatermarkGridHeight) / 2));
        }
        
        if ($repeatX || $repeatY) {
            // we need to create a repeated watermark buffer
            // we will create a buffer made of plain repeated watermark tiles surrounding the image and crop it after
            if ($repeatX) {
                if ($deltaX > 0) {
                    ++$cols;
                }
                ++$cols;
            }
            if ($repeatY) {
                if ($deltaY > 0) {
                    ++$rows;
                }
                ++$rows;
            }
            
            $palette = new RGB();
            $buffer = $this->getImagine()->create(new Box($cols * $watermark->getSize()->getWidth(), $rows * $watermark->getSize()->getHeight()), $palette->color([255, 255, 255], 0));
            
            for ($i = 0; $i < $cols; ++$i) {
                for ($j = 0; $j < $rows; ++$j) {
                    $buffer->paste($watermark, new Point($i * $watermark->getSize()->getWidth(), $j * $watermark->getSize()->getHeight()));
                }
            }
            
            if ($repeatX) {
                $width = $iImage->getSize()->getWidth();
                $cropX = (($watermark->getSize()->getWidth() - $deltaX) % $watermark->getSize()->getWidth());
            } else {
                $width = $watermark->getSize()->getWidth();
                $cropX = 0;
            }
            if ($repeatY) {
                $height = $iImage->getSize()->getHeight();
                $cropY = (($watermark->getSize()->getHeight() - $deltaY) % $watermark->getSize()->getHeight());
            } else {
                $height = $watermark->getSize()->getHeight();
                $cropY = 0;
            }
            
            $watermark = $buffer->crop(new Point($cropX, $cropY), new Box($width, $height));
            
            if ($repeatX) $deltaX = 0;
            if ($repeatY) $deltaY = 0;
        }
        
        $deltaP = new Point($deltaX, $deltaY);
        
        if ($this->handleAnimatedGif($image, function (IImage $iimage) use ($image) {
            // we take first frame conf
            /** @var IImage $iframe */
            $iframe = $iimage->layers()[0];
            $options = [
                'flatten' => false,
                'animated' => true,
                'animated.delay' => $iframe->getImagick()->getImageDelay() * 10,
                'animated.loop' => $iframe->getImagick()->getImageIterations(),
            ];
            // put those options for next binary dump only
            $image->setEphemeralImagineOptions($options);
            
        }, function (IImage $iframe) use ($watermark, $deltaP) {
            $iframe->paste($watermark, $deltaP);
        }, function (IImage $iimage) {
            // nothing
        })) {
            
            $image->deprecateBinaryContent();
            return;
        }
        $iImage->paste($watermark, $deltaP);
        $image->deprecateBinaryContent();
    }
511793
public function add_type($type, $path = null)
	{
		isset($this->_asset_paths[$type]) or $this->_asset_paths[$type] = array();
		isset($this->_path_folders[$type]) or $this->_path_folders[$type] = $type.'/';

		if ( ! is_null($path))
		{
			$path = $this->_unify_path($path);
			$this->_asset_paths[$type][] = $path;
		}

		return $this;
	}
542796
public function create($path = null)
    {
        $media = new $this->class();

        if ($path !== null) {
            $media->setFile(new \Symfony\Component\HttpFoundation\File\File($path));
        }

        return $media;
    }
1020158
public function file($key, $path=null) :self {
		// if we have an array of data
		if(is_array($key)) {
			// for each of those
			foreach($key as $index => $path) {
				// set them
				$this->file($index, $path);
			}
		}
		else {
			// add to the list of files
			$this->data[$key] = '@'.$path;
		}
		// return self
		return $this;
	}
1077618
public static function register($path = null)
    {
        self::$_path = $path ? $path : dirname(__FILE__);

        return spl_autoload_register([__CLASS__, 'load'], true, true);
    }
28796
public function withPath(string $path): self
    {
        $this->assertPresent($path);

        if ($this->path === $path) {
            return $this;
        }

        $clone = clone $this;
        $clone->path = $path;

        return $clone;
    }