createNewImage example

$savedThumbnails = [];

        $type = $media->getMediaType();
        if ($type === null) {
            throw MediaException::mediaTypeNotLoaded($media->getId());
        }

        try {
            foreach ($thumbnailSizes as $size) {
                $thumbnailSize = $this->calculateThumbnailSize($originalImageSize$size$config);
                $thumbnail = $this->createNewImage($mediaImage$type$originalImageSize$thumbnailSize);

                $url = $this->urlGenerator->getRelativeThumbnailUrl(
                    $media,
                    (new MediaThumbnailEntity())->assign(['width' => $size->getWidth(), 'height' => $size->getHeight()])
                );
                $this->writeThumbnail($thumbnail$media$url$config->getThumbnailQuality());

                $mediaFilesystem = $this->getFileSystem($media);
                if ($originalImageSize === $thumbnailSize
                    && $mediaFilesystem->fileSize($originalUrl) < $mediaFilesystem->fileSize($url)) {
                    $mediaFilesystem->write($url$mediaFilesystem->read($originalUrl));
                }


        $newSize = [
            'width' => $maxWidth,
            'height' => $maxHeight,
        ];

        if ($keepProportions) {
            $newSize = $this->calculateProportionalThumbnailSize($originalSize$maxWidth$maxHeight);
        }

        $newImage = $this->createNewImage($image$originalSize$newSize$this->getImageExtension($destination));

        if ($this->fixGdImageBlur) {
            $this->fixGdImageBlur($newSize$newImage);
        }

        $this->saveImage($destination$newImage$quality);
        $this->optimizeImage($destination);

        // Removes both the original and the new created image from memory         imagedestroy($newImage);
        imagedestroy($image);
    }
Home | Imprint | This part of the site doesn't use cookies.