From ea088183e7b572cb4c768c065bf9227dcb5250d1 Mon Sep 17 00:00:00 2001 From: Pavel Bychko Date: Fri, 3 Jun 2022 19:39:00 +0300 Subject: [PATCH] change make method --- src/OpenGraphImages.php | 21 ++++++++++++++++++--- tests/OpenGraphImagesTest.php | 7 +++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/OpenGraphImages.php b/src/OpenGraphImages.php index 8d3bd12..3789f9c 100644 --- a/src/OpenGraphImages.php +++ b/src/OpenGraphImages.php @@ -242,11 +242,26 @@ public function __construct(array $config = []) } } - public function make(string $text, int $width = 1200, int $height = 630): OpenGraphImages + public function make(string $text, string $preset = 'opengraph'): OpenGraphImages { // https://developers.facebook.com/docs/sharing/webmasters/images/ - $this->imageWidth = $width; - $this->imageHeight = $height; + // https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/summary-card-with-large-image + // https://dev.vk.com/api/posts + + $this->imageWidth = 1200; + switch (strtolower($preset)) { + case 'opengraph': + case 'facebook': + default: + $this->imageHeight = 630; + break; + case 'twitter': + $this->imageHeight = 600; + break; + case 'vk': + $this->imageHeight = 536; + break; + } $this->createImage($text); diff --git a/tests/OpenGraphImagesTest.php b/tests/OpenGraphImagesTest.php index 6ab63b9..892774d 100644 --- a/tests/OpenGraphImagesTest.php +++ b/tests/OpenGraphImagesTest.php @@ -30,6 +30,13 @@ public function testMake(string $text): void $result = $this->openGraphImages->make($text); $this->assertInstanceOf(OpenGraphImages::class, $result); $this->assertEquals('image/png', $this->getMimeTypeFromString($result->get())); + + $presets = ['opengraph', 'facebook', 'twitter', 'vk']; + foreach ($presets as $preset) { + $result = $this->openGraphImages->make($text, $preset); + $this->assertInstanceOf(OpenGraphImages::class, $result); + $this->assertEquals('image/png', $this->getMimeTypeFromString($result->get())); + } } /**