Download the PHP package 53ny4/og-image without Composer
On this page you can find all versions of the php package 53ny4/og-image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 53ny4/og-image
More information about 53ny4/og-image
Files in 53ny4/og-image
Package og-image
Short Description Generate Open Graph image for your website
License MIT
Informations about the package og-image
OG Image Generator in PHP 1.6.1 (GD Driver)
NOTE: This project is still in development.
A simple and flexible PHP library for generating Open Graph (OG) (but really any type of) images with customizable backgrounds, text, and watermarks. Perfect for creating dynamic social media preview images for your website or application.
This project was inspired by my clients, each of them wanted to have a custom OG image for their website. One wanted to have a simple image with a quote, another wanted to have an avatar of the user displayed and so on. While there are projects like that and don't get me wrong, they are great, but they are not flexible enough for my needs.
On the other hand, Imagine/Imagine is a great library, but it has a bit of code to write to get the desired result.
say, watermark, for example, you have to write a bit of code to get the desired result.
It is simpler than native GD, but still. I wanted it to be straightforward and simple, since I'm using it quite often.
Done.
Example Image
NOTE: all highlighted elements are separate layers, so you can easily customize them.
Image background with text and watermark.
Resized image background with text. (see original image here)
Image background with for quote.
Color background with borders and text.
Fancy Memorial Example
There are 3 watermarks elements in this example: the logo, fancy frame and a portrait and 2 text elements: name and dates.
as used at ForeverAfter.Life - OG
Table of Contents
- Features
- Requirements
- Installation
- Usage
- Basic Usage
- Setting Backgrounds
- Solid Color Background
- Image Background
- Adding Borders
- Adding Text
- Text Positioning
- Text Styling
- Background Rectangle for Text
- Adding Watermarks
- Custom Templates
- Full Example
- Customization
- Fonts
- Padding and Alignment
- License
Features
- Generate OG images or any image with custom dimensions.
- Set backgrounds using solid colors or images.
- Add borders (top,bottom,left,right) to the background.
- Add text with customizable font, size, color, and alignment.
- Wrap text automatically within a specified width.
- Add background rectangles behind text with adjustable opacity and padding.
- Include watermarks with adjustable size, position, and opacity.
- Custom templates for easy image generation.
Requirements
- PHP 8.2.
- Composer.
- GD library installed and enabled.
- imagine/imagine
Installation
-
Install the library using Composer:
-
Clone the Repository:
-
Install Dependencies:
Navigate to the project directory and install the required packages using Composer.
Ensure that the imagine/imagine package is installed and available in the project.
NOTE: only GD driver is used. Make sure that the GD library is installed and enabled in your PHP configuration.
Usage
Basic Usage
Here's a quick example of how to generate an OG image with a solid color background, border, watermark and custom text.
Setting Backgrounds
You can set the background of the image using a solid color or an image.
Solid Color Background
Image Background
Adding Borders
You can add borders to the background with custom width and color.
Adding Text
You can add multiple text elements to the image, each with its own styling and positioning.
Text Positioning
Position the text horizontally ('left'
, 'center'
, 'right'
) and vertically ('top'
, 'center'
, 'bottom'
).
Hint: you can use pixel values for custom positioning.
Text Styling
Customize the text color, size, and font.
Background for Text
Add a background rectangle behind the text with adjustable opacity.
Adding Watermarks
Add watermark image with customizable size, position, and opacity. (can be added multiple watermarks) Watermark treated as a separate layer, so you can add multiple watermarks and they can overlap each other.
Hint: watermark can be not only used as an actual watermark, but also as a logo or any other image. Also: you can use pixel values for custom positioning.
Custom Templates (How to)
Your custom templates should extend the OgImageTemplateBase
.
Then you can add your custom methods to the template with specific properties that you want to set.
And then in your code, instead of using a bunch of parameters, you can just use it like this:
Result:
Full Example
Putting it all together:
Customization
Fonts
- Default Font: The library comes with a default font located in
src/assets/fonts/
. - Custom Fonts: Use the
setFontFile
method to specify a custom font file.
Padding and Alignment
-
Vertical Padding: Adjust the vertical padding around the text using
setPadding
. -
Text Alignment: Control the horizontal alignment (
'left'
,'center'
,'right'
) and vertical alignment ('top'
,'center'
,'bottom'
). - Text Wrapping: Set a maximum width for text wrapping using
setMaxWidth
.
Note: Ensure all file paths are correct and that necessary assets (fonts, images) are available in the specified locations. Adjust permissions as needed to allow the script to read and write files.
Disclaimer: This library uses the GD library for image manipulation.
License
This project is licensed under the MIT License