Skip to content

Commit

Permalink
change make method
Browse files Browse the repository at this point in the history
  • Loading branch information
abordage committed Jun 3, 2022
1 parent 912448b commit ea08818
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/OpenGraphImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions tests/OpenGraphImagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

/**
Expand Down

0 comments on commit ea08818

Please sign in to comment.