This project is not covered by Drupal’s security advisory policy.
This module automatically replaces image styles with a tokenized text overlay like [node:title] with a node's data, such as the title, the author or creation-date of the node, which can be used as a beautiful and meaningful image for social media.
You can use the generated image for example as image source for the og:image meta tag:
<meta property="og:image" content="http://domain.tld/my-dynamic-image.png"/>
Release 2.0.x
This realease introduces a major restructuring of the module to provide a more flexible and robust architecture for dynamic image generation. It is easier to setup and to use.
The new release uses Drupal core image-styles and the effect “Text overlay” from the “Image Effects”-module with “Tokens” to dynamically build the images. This eliminates the need to implement the image layout programmatically.
There is no upgrade path from 1.x to 2.x.
Usage:
- Create an image style with an text overlay effect from the Image-Effects-Module. The text can (and should) contain node-tokens like [node:title], which will be replaced by this module..
Look inside the README.md for an example. - Visit the Settings-Page:
/admin/config/system/gsmi - Select the node-types image-field (for example "field_seo_image") and your new image style.
- Use the following tokens (for example in the meta-tags) to output the full path for the node's generated image:
[node:generate-style] -> Image styled with current image-style and field from settings-page
[node:generate-style:STYLE_MACHINE_NAME] -> … styled with current image-style
[node:generate-style:STYLE_MACHINE_NAME:FIELD_MACHINE_NAME] -> … with current image-style and field
The node-tokens [node:title] will be replaced by the node's title. And that's the magic of this module!
Release 1.0.x
You can use the generated image for example as image source like:
src="generate-social-media-image/returnasimage/123"
Or as a source for the og:image meta tag:
Please note:
The image will be generated by your server every time someone or something hits the path. There is no caching!
Pro: The image could be created depending on varying data, like time, user, weather or my account balance. ;-)
Contra: It can slow down your server if the image is called very often and at the same time.
For this reason, you must explicitly give permission for users, if you want allow them to generate images on the fly:
/admin/people/permissions/module/gsmi
Features:
The modules functions are based on the GD library.
Currently, the following functions, among others, are implemented:
Automatically generate the image for node [nid] on every call:
/generate-social-media-image/returnasimage/[nid]
Generate the image for node [nid] and save it to a managed file:
/generate-social-media-image/savetofile/[nid]
Generate the image to node [nid], save it as a file and create a new media image element
/generate-social-media-image/savetofile/[nid]/true
Token, which outputs the full path for the nodes generated image:
[node:generated-image]
Installation:
See the documentation on how to install sandbox-modules:
Add repository to your composer.json
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "vcs",
"url": "https://git.drupalcode.org/project/gsmi.git"
}
],
After that require the sandbox-module:
composer require drupal/gsmi:1.0.x-dev
Configuration:
You can change colors, fonts, sizes and source of the image at the configurations-page.
(Manage > Configuration > Media > Generate Social Media Image)
/admin/config/system/generate-social-media-image
At the end of the form, you can find a preview-image of your settings.
Don't forget to give permission to anyone who should be able to generate images!
/admin/people/permissions/module/gsmi
Can i create my own template for an automatic social media image?
Yes, you can: there is a hook_gsmi_imagelayout for that.
As an example and starting point on how to create your own template for an image, the module contains a sub-module "Generate Social Media Image (Example)" (gsmi_example).
You can switch the templates on the configurations-page.
Contact me if you need paid help in creating your own image template for social media.
Similar Modules:
Image Effects: "The Image Effects module provides a suite of additional image effects". Most of the layout-stuff can be done with this module and it is better suited if you need caching. But you cannot add variable data (like time, user-data, role, ...) to the generated image.
Image Generator: "This module generates an image on the fly from [url-]parameters.". If you don't need complex layouts, this module maybe will suit your needs, too.
Project information
- Project categories: Media, Search engine optimization (SEO)
- Ecosystem: Drupal Media, Metatags, image effect
- Created by tfranz on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.




