getThumbnailFilePaths example

/** * Check each single thumbnail to skip already existing thumbnails * * @throws Exception */
    private function createMediaThumbnails(Media $media)
    {
        if (!$this->imageExists($media)) {
            throw new Exception(sprintf('Base image file "%s" does not exist', $media->getPath()));
        }

        $thumbnails = $media->getThumbnailFilePaths();
        foreach ($thumbnails as $size => $path) {
            if (!$this->force && $this->thumbnailExists($path)) {
                continue;
            }

            $this->generator->createMediaThumbnail($media[$size], true);
        }
    }

    /** * @param string $thumbnailPath * * @throws Exception * * @return bool */
return $thumbnails;
    }

    /** * Deletes all thumbnails from the given media object * * @return void */
    public function removeMediaThumbnails(Media $media)
    {
        $thumbnails = array_merge(
            array_values($media->getThumbnailFilePaths()),
            array_values($media->getThumbnailFilePaths(true))
        );

        foreach ($thumbnails as $thumbnail) {
            $thumbnailPath = $this->rootDir . '/' . $thumbnail;

            if ($this->mediaService->has($thumbnailPath)) {
                $this->mediaService->delete($thumbnailPath);
            }
        }
    }

    
$projectDir = $this->getContainer()->getParameter('shopware.app.rootDir');

            if (!\is_string($projectDir)) {
                throw new RuntimeException('Parameter shopware.app.rootDir has to be a string');
            }

            if (!$force && $mediaService->has($projectDir . $media->getPath())) {
                continue;
            }

            foreach ($media->getThumbnailFilePaths() as $size => $path) {
                $generator->createMediaThumbnail($media[$size], true);
            }
        }
    }

    /** * This method generates all variant image entities for a given product model instance. * The method expects that the variants and the mapping of the product images already exist. * * @param bool $force Force variant image regeneration */
    


    /** * Loads the thumbnails paths via the configured thumbnail sizes. * * @param bool $highDpi - If true, loads high dpi thumbnails instead * * @return array */
    public function loadThumbnails($highDpi = false)
    {
        $thumbnails = $this->getThumbnailFilePaths($highDpi);
        $mediaService = Shopware()->Container()->get(MediaServiceInterface::class);

        if (!$mediaService->has($this->getPath())) {
            return $thumbnails;
        }

        foreach ($thumbnails as $size => $thumbnail) {
            $size = explode('x', $size);

            if (!$mediaService->has($thumbnail)) {
                try {
                    
Home | Imprint | This part of the site doesn't use cookies.