Synchronize thumbnail.

@param array $path
@return array
321813
public static function synchronizeThumbnail(array $path): array
    {
        $result = [];

        //TODO rebuild or removed - it was be lite check
//        // remove duplicate files
//        $counts = array_count_values($thumbFiles);
//        $duplicate = array_filter($counts, function ($row) { return $row > 1; });
//        foreach ($duplicate as $item => $count) {
//            $pathInfo = pathinfo($item);
//            $duplicateFinder = Finder::findFiles($pathInfo['filename'] . '*')->in(self::$parameters['thumbPath']);
//            foreach ($duplicateFinder as $duplicateItem) {
//                if (unlink($duplicateItem->getPathname())) {
//                    $result[] = $duplicateItem->getPathname();
//                }
//            }
//        }

        // load thumbnail files
        $thumbFiles = self::getThumbFiles();

        // load path files
        $pathFiles = self::getPathFiles($path);

        // remove different files
        $diff = array_diff($thumbFiles, $pathFiles);
        foreach ($diff as $oldName => $file) {
            if (unlink($oldName)) {
                $result[] = $oldName;
            }
        }
        return $result;
    }
1178850
protected function getFiles($path)
    {
        $path = Str::finish($path, '/');

        if (file_exists($path . App::getLocale())) {
            return File::files($path . App::getLocale());
        } elseif (file_exists($path . config('app.fallback_locale'))) {
            return File::files($path . config('app.fallback_locale'));
        }

        return [];
    }
769263
private function serveFromCache($path)
    {
        //try and load the image from the cache
        if ($this->cache->has($path)) {
            $file = $this->cache->get($path);

            $lastModified = new \DateTime();
            $lastModified->setTimestamp($file->getTimestamp());

            $this->setHttpCacheHeaders(
                $lastModified,
                md5($this->getCachePath().$lastModified->getTimestamp()),
                $this->maxAge
            );

            // Respond with 304 not modified
            if ($this->response->isNotModified($this->request)) {
                return true;
            }

            $this->response = new StreamedResponse();

            // Set the headers
            $this->response->headers->set('Content-Type', $file->getMimetype());
            $this->response->headers->set('Content-Length', $file->getSize());

            $this->setHttpCacheHeaders(
                $lastModified,
                md5($this->getCachePath().$lastModified->getTimestamp()),
                $this->maxAge
            );

            $this->response->setCallback(function () use ($file) {
                fpassthru($file->readStream());
            });

            return true;
        }

        return false;
    }
455881
protected function loadFile($path): array
    {
        $reader = ReaderFactory::get($this->builder, $path);

        return $reader->read($path);
    }
48429
public function imageExists($path) {
        $this->validateLocalFile($path);
        $checksum = md5_file($path);
        $query = new ImagesQuery();
        $query->originalChecksums(array($checksum))
              ->limit(1);

        $response = $this->getImages($query);

        return (boolean) $response['search']['hits'];
    }
180519
protected function _thumbnailImage(ImageWithImagineInterface $image, ImagePathInterface $path)
    {
        $this->assertImagine();
        $matches = null;
        if (!preg_match($this->pattern, $path->getPath(), $matches)) {
            return false;
        }
        
        if (is_callable($this->format)) {
            $format = call_user_func($this->format, $matches);
        } else {
            $format = $this->format;
        }
        
        if (false === $format) {
            // force a not found
            throw new ImageNotFoundException(sprintf('Image not found: %s', $path->getPath()));
        }
        
        if (is_null($format)) {
            // passthrough: we want the original image
            return true;
        }
        
        // not very LSP but handy
        if (!$image->getImagine()) {
            $image->setImagine($this->getImagine(), $this->getImagineOptions());
        }
        
        if (true === $format) {
            // we want the original image size but will trigger a save
            $image->deprecateBinaryContent();
            return true;
        }
        
        if (preg_match('/^(\<)?([0-9]+)x([0-9]+)$/', $format, $matches)) {
			$size = new \Imagine\Image\Box($matches[2], $matches[3]);
			$mode = $matches[1] == '<' ? \Imagine\Image\ImageInterface::THUMBNAIL_INSET : \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
		} elseif (preg_match('/^(\<)?([0-9]+)$/', $format, $matches)) {
			$size = new \Imagine\Image\Box($matches[2], $matches[2]);
			$mode = $matches[1] == '<' ? \Imagine\Image\ImageInterface::THUMBNAIL_INSET : \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
		} else {
			throw new ThumbnailRuleException(sprintf('Unsupported rule format: %s', (string)$format), ThumbnailRuleException::UNSUPPORTED_RULE_FORMAT);
		}
        
        /** @var IImage $animated */
        $animated = null;
        $imagine = $image->getImagine();
        if ($this->handleAnimatedGif($image, function (IImage $iimage) use ($imagine, $size, &$animated, $image) {
            $animated = $imagine->create($size);
            $animated->layers()->remove(0);
            $image->setImagineImage($animated);
            // 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(),
            ];
            $image->setEphemeralImagineOptions($options);
        }, function (IImage $iframe) use ($size, $mode, &$animated) {
            $animated->layers()->add($iframe->thumbnail($size, $mode));
        }, function (IImage $iimage) {
            // nothing
        })) {
            // nothing
            return true;
        }
        $image->setImagineImage($image->getImagineImage()->thumbnail($size, $mode, $this->filter));
		return true;
    }
966357
public function getMetadata(string $path): array
    {
        $parameters = [
            'path' => $this->normalizePath($path),
        ];

        return $this->rpcEndpointRequest('files/get_metadata', $parameters);
    }
145730
private function createImageFrom($path)
    {

        $this->gdExtensionCheck();
        switch ($this->getExt()) {
            case 'jpg':
                return imagecreatefromjpeg($path);
                break;
            case 'png':
                return imagecreatefrompng($path);
                break;
            case 'gif':
                return imagecreatefromgif($path);
                break;

            default:
                return imagecreatefrompng($path);
                break;
        }

    }
1048417
protected function normalizeMetaData($path)
    {
        $meta = $this->client->getObjectMeta($this->bucket, $path);
        if (is_null($meta)) {
            return false;
        }

        return [
            'path'      => $path,
            'timestamp' => strtotime($meta[strtolower('Last-Modified')]),
            'dirname'   => Util::dirname($path),
            'mimetype'  => $meta[strtolower('Content-Type')],
            'size'      => $meta[strtolower('Content-Length')],
            'type'      => 'file',
        ];
    }
670965
private function createArrayByPath($path)
    {
        $keys = explode('.', $path);
        $val = true;
        $localArray = [];
        for ($i=count($keys)-1; $i>=0; $i--) {
            $localArray = [$keys[$i]=>$val];
            $val = $localArray;
        }
        return $localArray;
    }
129427
public function getTimestamp($path)
    {
        $meta = $this->getMetadata($path);

        return isset($meta['LastModified'])
            ? ['timestamp' => strtotime($meta['LastModified'])] : false;
    }
534181
public static function decodeFromFile($path)
    {
        if (!is_file($path)) {
            throw new \Exception("File does not exist: {$path}");
        }

        $string = file_get_contents($path);

        if ($string === false) {
            throw new \Exception("Failed to read the file: {$path}");
        }

        if (!$string) {
            return [];
        }

        $array = json_decode($string, true);

        static::checkLastError();

        return $array;
    }
379126
public static function glob_recursive( $path ) {
		$files = [];
		if ( preg_match( '/\\' . DIRECTORY_SEPARATOR . 'vendor$/', $path ) ) {
			return $files;
		}

		foreach ( glob( $path . '/*' ) as $file ) {
			if ( is_dir( $file ) ) {
				$files = array_merge( $files, static::glob_recursive( $file ) );
			} elseif ( preg_match( '/\.php$/', $file ) ) {
				$files[] = $file;
			}
		}

		return $files;
	}
14635
private static function getVersionFrom($path)
    {
        $matches = [];
        preg_match(self::$semverRegex, $path, $matches);

        return array_shift($matches);
    }
349834
private function ls72(string $path) : array
    {
        $list = [];
        foreach ($this->mlsd($path) as $fileInfo) {
            $list[] = new File($fileInfo);
        }
        return $list;
    }
1122543
protected function getConfigurationFiles($path)
	{
		$files = [];

		foreach (Finder::create()->files()->name('*.php')->in($path) as $file)
		{
			$files[basename($file->getRealPath(), '.php')] = $file->getRealPath();
		}

		return $files;
	}
342742
public function load($path)
    {
        $path = $this->findAbsolutePath($path);

        if ($this->cache) {
            if ($this->cache->isFresh($path, filemtime($path))) {
                $feature = $this->cache->read($path);
            } elseif (null !== $feature = $this->parseFeature($path)) {
                $this->cache->write($path, $feature);
            }
        } else {
            $feature = $this->parseFeature($path);
        }

        return null !== $feature ? array($feature) : array();
    }