From b6a332ec9393bcf73d66fe05cec1757740bff7aa Mon Sep 17 00:00:00 2001 From: Rico van Zelst Date: Mon, 8 Jan 2024 14:14:44 +0100 Subject: [PATCH 1/4] chore(gitignore): add .idea/ to ignore list Add .idea/ directory to the ignore list in .gitignore file. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a6197de..1172c3d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ /node_modules /phpunit.xml /.phpunit.cache + +.idea/ From 731bbb552fcd890b8f6593ceaeb966e5cb0a61eb Mon Sep 17 00:00:00 2001 From: Rico van Zelst Date: Mon, 8 Jan 2024 14:18:08 +0100 Subject: [PATCH 2/4] docs(storage): add example code for uploading image to S3 Added an example snippet about how to upload an image generated by to an S3 compatible storage service. --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index ca3b83a..cdfba51 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,51 @@ And here's the image that generates: ![](https://github.com/simonhamp/the-og/blob/main/tests/Integration/__snapshots__/ImageTest__test_basic_image%20with%20data%20set%20override%20some%20elements__1.png) +#### Storing the image elsewhere + +If you don't have filesystem access or you'd just like to directly store your image on a storage service like Amazon S3 you can do so by using `toString()`. +`toString()` will return the encoded image object as a string. + +Here's an example of uploading your image to an S3 compatible storage service: + +```php +use Aws\S3\S3Client; +use SimonHamp\TheOg\Background; +use SimonHamp\TheOg\Image; + +$s3 = new S3Client([ + 'version' => 'latest', + 'region' => 'auto', + 'credentials' => [ + 'key' => 'your-access-key', + 'secret' => 'your-secret-key', + ], + 'endpoint' => 'your-s3-compatible-endpoint', +]); + +$bucketName = 'og-test-bucket'; + +$image = (new Image()) + ->accentColor('#cc0000') + ->border() + ->url('https://example.com/blog/some-blog-post-url') + ->title('Some blog post title that is quite big and quite long') + ->description('Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words') + ->background(Background::JustWaves, 0.2) + ->toString(); + + +$s3->putObject([ + 'Bucket' => $bucket, + 'Key' => 'example-image.png', + 'Body' => $image, + 'ContentType' => 'image/png', + 'ACL' => 'public-read', +]); +``` + +The image has now been uploaded to S3 and you can serve it from your public bucket URL. + ### Themes Themes set the colors, fonts, and styles for your image. There are currently 2 themes available: `Light` and `Dark`. From a1290b671ccedae9f51189fece3d93188aaff880 Mon Sep 17 00:00:00 2001 From: Rico van Zelst Date: Mon, 8 Jan 2024 14:22:32 +0100 Subject: [PATCH 3/4] docs(readme): fix typo in themes section - Fixed a typo in the theme name from `Theme::Dark` to `Themes::Dark` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cdfba51..faf2758 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ You can set the theme on your image at any point before it's rendered: ```php $image = new Image; -$image->theme(Theme::Dark); +$image->theme(Themes::Dark); ``` #### Creating themes From 9e1a3c13c4e8adc9b790e8d7a4db4b9fee0a1b01 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Mon, 8 Jan 2024 13:54:16 +0000 Subject: [PATCH 4/4] Simplify and restructure --- README.md | 66 ++++++++++++++++++------------------------------------- 1 file changed, 21 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index faf2758..6fbdc71 100644 --- a/README.md +++ b/README.md @@ -47,51 +47,6 @@ And here's the image that generates: ![](https://github.com/simonhamp/the-og/blob/main/tests/Integration/__snapshots__/ImageTest__test_basic_image%20with%20data%20set%20override%20some%20elements__1.png) -#### Storing the image elsewhere - -If you don't have filesystem access or you'd just like to directly store your image on a storage service like Amazon S3 you can do so by using `toString()`. -`toString()` will return the encoded image object as a string. - -Here's an example of uploading your image to an S3 compatible storage service: - -```php -use Aws\S3\S3Client; -use SimonHamp\TheOg\Background; -use SimonHamp\TheOg\Image; - -$s3 = new S3Client([ - 'version' => 'latest', - 'region' => 'auto', - 'credentials' => [ - 'key' => 'your-access-key', - 'secret' => 'your-secret-key', - ], - 'endpoint' => 'your-s3-compatible-endpoint', -]); - -$bucketName = 'og-test-bucket'; - -$image = (new Image()) - ->accentColor('#cc0000') - ->border() - ->url('https://example.com/blog/some-blog-post-url') - ->title('Some blog post title that is quite big and quite long') - ->description('Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words') - ->background(Background::JustWaves, 0.2) - ->toString(); - - -$s3->putObject([ - 'Bucket' => $bucket, - 'Key' => 'example-image.png', - 'Body' => $image, - 'ContentType' => 'image/png', - 'ACL' => 'public-read', -]); -``` - -The image has now been uploaded to S3 and you can serve it from your public bucket URL. - ### Themes Themes set the colors, fonts, and styles for your image. There are currently 2 themes available: `Light` and `Dark`. @@ -100,6 +55,8 @@ The default theme is `Light`. You can set the theme on your image at any point before it's rendered: ```php +use SimonHamp\TheOg\Themes\Themes; + $image = new Image; $image->theme(Themes::Dark); ``` @@ -150,6 +107,25 @@ There are currently 2 layouts: `Standard` and `GitHubBasic`. `Standard` is the d More layouts are coming. +### Storing the image elsewhere + +If you prefer to store your image somewhere other than the local filesystem (e.g. storing it on Amazon S3) you can use the `toString()` method. + +`toString()` will return the rendered image as a binary string: + +```php +$image = (new Image())->toString(); + +// $service here could be an AWS\S3\S3Client, for example +$service->putObject([ + 'Key' => 'example-image.png', + 'Body' => $image, + 'ContentType' => 'image/png', +]); +``` + +This will send the raw binary data directly to the external service without needing to write the image to a file on the local disk first. + ## Testing The OG uses [snapshot testing](https://github.com/spatie/phpunit-snapshot-assertions). To run the integration tests,