From 357cadb038a92c8e8bb37d9edf82151df7fb4cbb Mon Sep 17 00:00:00 2001 From: Pavel Bychko Date: Fri, 3 Jun 2022 19:54:39 +0300 Subject: [PATCH] add makeCustom method --- src/OpenGraphImages.php | 10 ++++++++++ tests/OpenGraphImagesTest.php | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/OpenGraphImages.php b/src/OpenGraphImages.php index 552465e..ba2fd05 100644 --- a/src/OpenGraphImages.php +++ b/src/OpenGraphImages.php @@ -271,6 +271,16 @@ public function make(string $text, string $preset = 'opengraph'): OpenGraphImage return $this; } + public function makeCustom(string $text, int $width = 1200, int $height = 630): OpenGraphImages + { + $this->imageWidth = $width; + $this->imageHeight = $height; + + $this->createImage($text); + + return $this; + } + public function get(): ?string { return $this->imageBlob; diff --git a/tests/OpenGraphImagesTest.php b/tests/OpenGraphImagesTest.php index 70a90cf..08ac01c 100644 --- a/tests/OpenGraphImagesTest.php +++ b/tests/OpenGraphImagesTest.php @@ -39,6 +39,24 @@ public function testMake(string $text): void } } + /** + * @dataProvider textProvider + */ + public function testMakeCustom(string $text): void + { + $sizesCollection = [ + [500, 500], + [600, 400], + ]; + + foreach ($sizesCollection as $sizes) { + [$width, $height] = $sizes; + $result = $this->openGraphImages->makeCustom($text, $width, $height); + $this->assertInstanceOf(OpenGraphImages::class, $result); + $this->assertEquals('image/png', $this->getMimeTypeFromString($result->get())); + } + } + /** * @dataProvider textProvider */