getThumbnailSize example



        // Get filename and extension in order to insert thumbnail size later         $extension = pathinfo($hash, PATHINFO_EXTENSION);
        $fileName = pathinfo($hash, PATHINFO_FILENAME);

        // Get thumbnail sizes         $sizes = [];
        if ($this->articleMediaAlbum) {
            $settings = $this->articleMediaAlbum->getSettings();
            if ($settings) {
                $sizes = $settings->getThumbnailSize();
            }
        }

        $sizes = array_map(function D$size) {
            $parts = explode('x', $size);

            return [
                'width' => $parts[0],
                'height' => $parts[1],
            ];
        }$sizes);

        

    public function createThumbnailsAction()
    {
        $offset = $this->Request()->getParam('offset');
        $limit = $this->Request()->getParam('limit');
        $albumId = $this->Request()->getParam('albumId');

        $medias = $this->getMediaForAlbumId($albumId$offset$limit);

        $settings = $this->getAlbumSettings($albumId);
        $thumbnailSizes = $settings->getThumbnailSize();

        if (empty($thumbnailSizes) || empty($thumbnailSizes[0])) {
            $this->View()->assign(['success' => false]);

            return;
        }

        /** @var Manager $manager */
        $manager = $this->get(Manager::class);

        $fails = [];
        
/** * @throws Exception */
    private function getThumbnailSizesFromMedia(Media $media): array
    {
        $settings = $media->getAlbum()->getSettings();

        if (!$settings instanceof Settings) {
            throw new Exception('No settings configured in the album of the given media object!');
        }

        $thumbnailSizes = $settings->getThumbnailSize();

        // When no sizes are defined in the album         if (empty($thumbnailSizes) || empty($thumbnailSizes[0])) {
            $thumbnailSizes = [];
        }

        return $thumbnailSizes;
    }

    private function getAlbumSettingsFromMedia(Media $media): ?Settings
    {
        
if ($isNameChanged) {
                // Remove default thumbnails                 $this->removeDefaultThumbnails($name);

                // Create default thumbnails                 $this->createDefaultThumbnails();
            }

            // Remove the configured album thumbnail files             $settings = $album->getSettings();
            if ($settings !== null) {
                $this->removeAlbumThumbnails($settings->getThumbnailSize()$name);
            }

            $this->updateAssociations();

            // Create album thumbnails             $this->createAlbumThumbnails($this->album);
        }

        // Name changed? Then rename the file and set the new path         if ($isNameChanged) {
            $mediaService = Shopware()->Container()->get(MediaServiceInterface::class);
            
private function getDataOfProductImage(?array $image, Album $productAlbum): array
    {
        // Initial the data array         $imageData = [];
        $mediaService = Shopware()->Container()->get(MediaServiceInterface::class);

        if (empty($image['path'])) {
            return $imageData;
        }

        // First we get all thumbnail sizes of the product album         $sizes = $productAlbum->getSettings()->getThumbnailSize();

        $highDpiThumbnails = $productAlbum->getSettings()->isThumbnailHighDpi();

        // If no extension is configured, shopware use jpg as default extension         if (empty($image['extension'])) {
            $image['extension'] = 'jpg';
        }

        $imageData['src']['original'] = $mediaService->getUrl($image['media']['path']);
        $imageData['res']['original']['width'] = $image['width'];
        $imageData['res']['original']['height'] = $image['height'];
        
Home | Imprint | This part of the site doesn't use cookies.