cannotCreateImage example



    /** * @param array{width: int, height: int} $originalImageSize * @param array{width: int, height: int} $thumbnailSize */
    private function createNewImage(\GdImage $mediaImage, MediaType $type, array $originalImageSize, array $thumbnailSize): \GdImage
    {
        $thumbnail = imagecreatetruecolor($thumbnailSize['width']$thumbnailSize['height']);

        if ($thumbnail === false) {
            throw MediaException::cannotCreateImage();
        }

        if (!$type->is(ImageType::TRANSPARENT)) {
            $colorWhite = (int) imagecolorallocate($thumbnail, 255, 255, 255);
            imagefill($thumbnail, 0, 0, $colorWhite);
        } else {
            imagealphablending($thumbnail, false);
        }

        imagesavealpha($thumbnail, true);
        imagecopyresampled(
            
$exception = MediaException::thumbnailCouldNotBeSaved($url);

        static::assertEquals(Response::HTTP_CONFLICT, $exception->getStatusCode());
        static::assertEquals(MediaException::MEDIA_THUMBNAIL_NOT_SAVED, $exception->getErrorCode());
        static::assertEquals('Thumbnail could not be saved to location: http://url.', $exception->getMessage());
        static::assertEquals(['location' => $url]$exception->getParameters());
    }

    public function testCannotCreateImage(): void
    {
        $exception = MediaException::cannotCreateImage();

        static::assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $exception->getStatusCode());
        static::assertEquals(MediaException::MEDIA_CANNOT_CREATE_IMAGE_HANDLE, $exception->getErrorCode());
        static::assertEquals('Can not create image handle.', $exception->getMessage());
    }

    public function testMediaContainsNoThumbnails(): void
    {
        $exception = MediaException::mediaContainsNoThumbnails();

        static::assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $exception->getStatusCode());
        
Home | Imprint | This part of the site doesn't use cookies.