@param Asset    $asset
@param string   $filename
@param string   $path
@param int|null $width
@param int|null $height
@param null     $taskId

@return bool
@throws \yii\base\InvalidConfigException
776001
public function resize(Asset $asset, string $filename, string $path, int $width = null, int $height = null, $taskId = null): bool
    {
        $volume = $asset->getVolume();

        // Does the volume exist?
        if (!$volume) {
            ImageResizer::$plugin->logs->resizeLog($taskId, 'skipped-no-volume', $filename);

            return false;
        }

        // Is this a manipulatable image?
        if (!ImageHelper::canManipulateAsImage(@pathinfo($path, PATHINFO_EXTENSION))) {
            ImageResizer::$plugin->logs->resizeLog($taskId, 'skipped-non-image', $filename);

            return false;
        }

        try {
            $settings = ImageResizer::$plugin->getSettings();
            $image = Craft::$app->images->loadImage($path);

            // Save some existing properties for logging (see savings)
            $originalProperties = [
                'width'  => $image->getWidth(),
                'height' => $image->getHeight(),
                'size'   => filesize($path),
            ];

            // We can have settings globally, or per asset source. Check!
            // Our maximum width/height for assets from plugin settings
            $imageWidth = ImageResizer::$plugin->service->getSettingForAssetSource($asset->volumeId, 'imageWidth');
            $imageHeight = ImageResizer::$plugin->service->getSettingForAssetSource($asset->volumeId, 'imageHeight');

            // Allow for overrides passed on-demand
            $imageWidth = $width ? $width : $imageWidth;
            $imageHeight = $height ? $height : $imageHeight;

            // Check to see if we should make a copy of our original image first?
            if ($settings->nonDestructiveResize) {
                $folderPath = 'originals/';

                // Create a new folder 'originals'
                if (!$volume->folderExists($folderPath)) {
                    $volume->createDir($folderPath);
                }

                $filePath = $folderPath . $filename;

                // Only copy the original if there's not already one created
                if (!$volume->fileExists($filePath)) {
                    $stream = @fopen($path, 'rb');
                    $volume->createFileByStream($filePath, $stream, []);

                    // Spin up asset indexer
                    Craft::$app->getAssetIndexer()->indexFile($volume, $filePath);
                }
            }

            // Lets check to see if this image needs resizing. Split into two steps to ensure
            // proper aspect ratio is preserved and no upscaling occurs.
            $hasResized = false;

            if ($image->getWidth() > $imageWidth) {
                $hasResized = true;
                $this->_resizeImage($image, $imageWidth, null);
            }

            if ($image->getHeight() > $imageHeight) {
                $hasResized = true;
                $this->_resizeImage($image, null, $imageHeight);
            }

            if ($hasResized) {
                // Set image quality - but normalise (for PNG)!
                if (method_exists($image, 'setQuality')) {
                    $image->setQuality(ImageResizer::$plugin->service->getImageQuality($path));
                }

                // If we're checking for larger images
                if ($settings->skipLarger) {
                    // Save this resized image in a temporary location - we need to test filesize difference
                    $tempPath = AssetsHelper::tempFilePath($filename);
                    ImageResizer::$plugin->service->saveAs($image, $tempPath);

                    clearstatcache();

                    // Lets check to see if this resize resulted in a larger file - revert if so.
                    if (filesize($tempPath) < filesize($path)) {
                        ImageResizer::$plugin->service->saveAs($image, $path); // Its a smaller file - properly save

                        // Create remote file
                        // if (!$volume instanceof LocalVolumeInterface) {
                        //     $this->_createRemoteFile($volume, $filename, $path);
                        // }

                        clearstatcache();

                        $newProperties = [
                            'width'  => $image->getWidth(),
                            'height' => $image->getHeight(),
                            'size'   => filesize($path),
                        ];

                        ImageResizer::$plugin->logs->resizeLog($taskId, 'success', $filename, ['prev' => $originalProperties, 'curr' => $newProperties]);
                    } else {
                        ImageResizer::$plugin->logs->resizeLog($taskId, 'skipped-larger-result', $filename);
                    }

                    // Delete our temp file we test filesize with
                    @unlink($tempPath);
                } else {
                    ImageResizer::$plugin->service->saveAs($image, $path);

                    // Create remote file
                    // if (!$volume instanceof LocalVolumeInterface) {
                    //     $this->_createRemoteFile($volume, $filename, $path);
                    // }

                    clearstatcache();

                    $newProperties = [
                        'width'  => $image->getWidth(),
                        'height' => $image->getHeight(),
                        'size'   => filesize($path),
                    ];

                    ImageResizer::$plugin->logs->resizeLog($taskId, 'success', $filename, ['prev' => $originalProperties, 'curr' => $newProperties]);
                }
            } else {
                ImageResizer::$plugin->logs->resizeLog($taskId, 'skipped-under-limits', $filename);
            }

            return true;
        } catch (\Exception $e) {
            ImageResizer::$plugin->logs->resizeLog($taskId, 'error', $filename, ['message' => $e->getMessage()]);

            return false;
        }
    }
888152
private function loadHandler( $asset )
    {
        // objects of class configurable
        if( is_callable($asset) ) {

            return call_user_func($asset, $this, $this->container);

        // this looks like a file name
        // because we're not taking relative paths look for 1st character being a string
        } elseif ( is_string($asset) and 0 === strpos($asset, '/') and file_exists($asset) ) {

            $yamlFileLoader = new YamlFileLoader(
                $this->container,
                new FileLocator(dirname($asset))
            );
            return $yamlFileLoader->load(basename($asset));

        } elseif ( is_string($asset) and class_exists( $asset ) /* and is_a( $asset, DiConfigurable::class ) */ ) {

            $invokedAsset = new $asset();
            if( !method_exists( $asset, '__invoke' ) ) {
                throw new ClassNotAConfigurableException($asset);
            }
            return call_user_func($invokedAsset, $this, $this->container);

        }

        throw new UnrecognisedAssetException($asset);
    }
68223
public static function fromFile($filename, $width, $height = 0)
    {
        
        $urlizer = new Urlizer($filename);

        static::configureUrlizer($urlizer);

        // If the filename is not initialized by '/', this is a fullpath
        
        if (strpos($filename, '/') !== 0) {

            $filename = $urlizer->getPublicFilename();
        }

        try {

            $thumb = new static($filename, $width, $height);

        } catch (\InvalidArgumentException $e) {

            if (static::$config['fallback'] === null) {

                throw $e;
            }

            return static::$config['fallback'];
        }

        $basename = $thumb->generateBasename();

        $filename = $urlizer->buildThumbFilename($basename);

        $thumb->getCache($filename);

        return $urlizer->buildThumbUrl($basename);
    }
817014
public static function asset(string $path, string $assetKey = null): Redirect
    {
        return self::temporary(Route::asset($path, $assetKey));
    }
1306581
public function setFilters($path, AssetInterface $asset)
    {
        $filters = $this->getFilters($path, $asset);

        foreach ($filters as $filter) {
            $this->setFilter($filter, $asset);
        }
    }
437395
public function lookup($context, $path, $require = false)
    {
        if (empty($path)) {
            throw new \InvalidArgumentException("Passed lookup path is empty.");
        }
        if (empty($context)) {
            throw new \InvalidArgumentException("Specified context is empty while resolving path " . json_encode($path));
        }
        return PropertyAccessor::getByPath($context, $this->path($path), $require);
    }
1352217
public static function load(string $path = null, array $paths = []): self
    {
        if (null === $path) {
            $config = [];
        } else {
            if (false === (new Filesystem())->isAbsolutePath($path)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected the path of the configuration file to load to be an absolute path, got "%s" '
                        .'instead',
                        $path
                    )
                );
            }

            if (false === file_exists($path)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected the path of the configuration file to exists but the file "%s" could not be '
                        .'found',
                        $path
                    )
                );
            }

            if (false === is_file($path) && false === (is_link($path) && is_file(readlink($path)))) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected the path of the configuration file to be a file but "%s" appears to be a '
                        .'directory.',
                        $path
                    )
                );
            }

            $config = include $path;

            if (false === is_array($config)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected configuration to be an array, found "%s" instead.',
                        gettype($config)
                    )
                );
            }
        }

        self::validateConfigKeys($config);

        $prefix = self::retrievePrefix($config);

        $whitelistedFiles = null === $path ? [] : self::retrieveWhitelistedFiles(dirname($path), $config);

        $patchers = self::retrievePatchers($config);

        array_unshift($patchers, new SymfonyPatcher());

        $whitelist = self::retrieveWhitelist($config);

        $finders = self::retrieveFinders($config);
        $filesFromPaths = self::retrieveFilesFromPaths($paths);
        $filesWithContents = self::retrieveFilesWithContents(chain($filesFromPaths, ...$finders));

        return new self($path, $prefix, $filesWithContents, $patchers, $whitelist, $whitelistedFiles);
    }
460317
public function runTaskNow($taskName)
    {
        $tasks = $this->loader->loadTasks();

        foreach ($tasks as $task) {
            if ($task->getName() === $taskName) {
                return $this->executeTask($task);
            }
        }

        throw new \InvalidArgumentException('Task ' . $taskName . ' not found');
    }
1149081
private function loadAssetsFromConfig($content, $dir, $type = null, $isFromVendor = false, $siteName = '')
    {
        $newContent = $content;
        $assetsConfig = $dir.'assets.config.php';
        /**
         * check if the config exist
         */
        if (file_exists($assetsConfig)) {
            $files = include($assetsConfig);
            /**
             * check if assets config is not empty
             */
            if (!empty($files)) {
                foreach($files as $key => $file){
                    /**
                     * check if type to know what asset are
                     * we going to load
                     */
                    if(empty($type)) {
                        /**
                         * this will load the assets from the config
                         */
                        $cssToAdd = "\n";
                        $jsToLoad = "\n";
                        if (strtolower($key) == 'css') {
                            foreach ($file as $k => $css) {
                                $css = str_replace('/public', '', $css);
                                $css = $this->editFileName($css, $isFromVendor, $siteName);
                                $cssToAdd .= '<link href="' . $css . '" media="screen" rel="stylesheet" type="text/css">' . "\n";
                            }
                        }
                        elseif (strtolower($key) == 'js') {
                            foreach ($file as $k => $js) {
                                $js = str_replace('/public', '', $js);
                                $js = $this->editFileName($js, $isFromVendor, $siteName);
                                $jsToLoad .= '<script type="text/javascript" src="' . $js . '"></script>' . "\n";
                            }
                        }
                        $newContent = $this->createLink($newContent, $cssToAdd, $jsToLoad);
                    }
                    elseif($type == 'css'){
                        /**
                         * this will load only the css
                         * from the config
                         */
                        if (strtolower($key) == 'css') {
                            $cssToAdd = "\n";
                            foreach ($file as $k => $css) {
                                $css = str_replace('/public', '', $css);
                                $css = $this->editFileName($css, $isFromVendor, $siteName);
                                $cssToAdd .= '<link href="' . $css . '" media="screen" rel="stylesheet" type="text/css">' . "\n";
                            }
                            $newContent = $this->createCssLink($content, $cssToAdd);
                        }
                    }elseif($type == 'js'){
                        /**
                         * this will load the js only from the config
                         */
                        if (strtolower($key) == 'js') {
                            $jsToLoad = "\n";
                            foreach ($file as $k => $js) {
                                $js = str_replace('/public', '', $js);
                                $js = $this->editFileName($js, $isFromVendor, $siteName);
                                $jsToLoad .= '<script type="text/javascript" src="' . $js . '"></script>' . "\n";
                            }
                            $newContent = $this->createJsLink($content, $jsToLoad);
                        }
                    }
                }
            }
        }
        return $newContent;
    }
956782
public function setAsset($path)
	{		
		$url = $this->config['dir']['site'] . str_replace($this->config['dir']['asset'], '', $path);
		$this->assets[] = new Asset($path, $url);
	}
868040
public function createAssetUrl($module = null, $path = null)
    {
        if (is_null($module)) {
            $module = $this->module;
        }

        return sprintf('/%s/%s/%s', self::TEMPLATE_PARAM_MODULES_DIR, $module, self::TEMPLATE_PARAM_ASSETS_DIR) . $path;
    }
158060
public function add(FileAssetInterface $asset)
    {
        if (!$asset->getPackageName()) {
            // Deprecated.
            $asset->setPackageName('extensions');
        }

        $key = $asset->getPackageName()."/".$asset->getPath();

        if ($asset->getType() === 'javascript') {
            $this->javascript[$key] = $asset;
        } elseif ($asset->getType() === 'stylesheet') {
            $this->stylesheet[$key] = $asset;
        } else {
            throw new \InvalidArgumentException(sprintf('Requested asset type %s is not valid.', $asset->getType()));
        }
    }
670426
public function assetPath($path = null)
    {
        return ! is_null($path) ? $this->assetDir().'/'.ltrim($path, '/') : $this->assetDir();
    }
320133
public function setFilters($path, AssetInterface $asset)
    {
        $config = $this->getConfig();

        if (!empty($config[$path])) {
            $filters = $config[$path];
        } elseif (!empty($config[$asset->mimetype])) {
            $filters = $config[$asset->mimetype];
        } else {
            $extension = $this->getMimeResolver()->getExtension($asset->mimetype);
            if (!empty($config[$extension])) {
                $filters = $config[$extension];
            } else {
                return;
            }
        }

        foreach ($filters as $filter) {
            if (is_null($filter)) {
                continue;
            }
            if (!empty($filter['filter'])) {
                $this->ensureByFilter($asset, $filter['filter']);
            } elseif (!empty($filter['service'])) {
                $this->ensureByService($asset, $filter['service']);
            } else {
                throw new Exception\RuntimeException(
                    'Invalid filter supplied. Expected Filter or Service.'
                );
            }
        }
    }
952666
public function setAssetsPath($path) {
		$path = realpath(rtrim($path, DIRECTORY_SEPARATOR));
		
		if ($path === false || ! is_readable($path)) {
			throw new InvalidPath('Path to the assets must exists and be readable');
		}
		
		$this->assetsPath = $path;
	}
1365151
protected function loggingFileAsset($assets, $type = self::ASSET_CSS_FILE, array $options = [], $key = null)
    {
        if (!$assets) {
            throw new InvalidArgumentException('The 1th param [$assets] is can\'t empty.');
        }

        $pos = trim($options['position']);
        $this->checkTypeAndPosition($type, $pos);

        foreach ((array)$assets as $name => $asset) {
            $asset = trim($asset);

            // check asset url
            if (\in_array($type, [self::ASSET_JS_FILE, self::ASSET_CSS_FILE], true)) {
                $asset = AssetLoad::buildUrl($asset, $this->getBaseUrl(), $this->basePath, false);
            }

            $tag = $this->buildTag($asset, $type);

            if (!is_numeric($name)) {
                // if ( $this->lockedCheck($name, $pos) ) {
                //     # code...
                // }

                $this->assets[$pos][$name] = $tag;
            } else {
                $this->assets[$pos][] = $tag;
            }
        }

        return $this;
    }
1187493
private static function hasDirectory(Event $event, $config_name, $path, $action_name)
    {
        if (!is_dir($path)) {
            $event->getIO()->write(sprintf(
                'The %s (%s) specified in composer.json was not found in %s, can not %s.',
                $config_name,
                $path,
                getcwd(),
                $action_name
            ));

            return false;
        }

        return true;
    }