createMediaThumbnail example


        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 */
    private function thumbnailExists($thumbnailPath)
    {

    private function createDefaultThumbnails()
    {
        // Create only thumbnails for image media         if ($this->type !== self::TYPE_IMAGE) {
            return;
        }

        /** @var Manager $generator */
        $generator = Shopware()->Container()->get(Manager::class);

        $generator->createMediaThumbnail($this$this->defaultThumbnails, true);
    }

    /** * Removes the default thumbnail files. The file name have to be passed, because on update the internal * file name property is already changed to the new name. * * @param string $fileName */
    private function removeDefaultThumbnails($fileName)
    {
        if ($this->type !== self::TYPE_IMAGE) {
            
// Set the upload file into the model. The model saves the file to the directory             $media->setFile($file);

            // Persist the model into the model manager             $this->get('models')->persist($media);
            $this->get('models')->flush();
            $data = $this->getMedia($media->getId())->getQuery()->getArrayResult();

            if ($media->getType() === Media::TYPE_IMAGE // GD doesn't support the following image formats                 && !\in_array($media->getExtension()['tif', 'tiff'], true)) {
                $manager = $this->get(Manager::class);
                $manager->createMediaThumbnail($media[], true);
            }

            $mediaService = $this->get(MediaServiceInterface::class);
            $data[0]['path'] = $mediaService->getUrl($data[0]['path']);

            $this->View()->assign(['success' => true, 'data' => $data[0]]);
        } catch (Exception $e) {
            unlink($file->getPathname());

            $this->View()->assign(['success' => false, 'message' => $e->getMessage(), 'exception' => $this->parseExceptionForResponse($e)]);
        }
    }
$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 */
    public function generateVariantImages(ProductModel $article$force = false)
    {
throw new ValidationException($violations);
        }

        $this->getManager()->persist($attribute);
        $this->getManager()->persist($media);
        $this->flush();

        if ($media->getType() === MediaModel::TYPE_IMAGE) {
            /** @var Manager $manager */
            $manager = $this->getContainer()->get(Manager::class);

            $manager->createMediaThumbnail($media[], true);
        }

        return $media;
    }

    /** * @param int $id * * @throws NotFoundException * @throws ParameterMissingException * @throws CustomValidationException * * @return MediaModel */
if ($imageSize) {
                $media->setWidth($imageSize[0]);
                $media->setHeight($imageSize[1]);
            }

            $media->removeThumbnails();

            if ($newFileName) {
                $media->setPath($newFileName);
            }

            $this->thumbnailManager->createMediaThumbnail($media$media->getDefaultThumbnails(), true);
            $media->createAlbumThumbnails($media->getAlbum());
        } elseif ($newFileName) {
            $media->setPath($newFileName);
        }

        $this->modelManager->flush();
    }

    /** * @return string */
    
Home | Imprint | This part of the site doesn't use cookies.