53ny4/og-image
Composer 安装命令:
composer require 53ny4/og-image
包简介
Generate Open Graph image for your website
关键字:
README 文档
README
Table of Contents
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.
Example
Code for the above image:
$og = new OgImageGenerator(); $og->setBackgroundImage('src/assets/images/bg.png'); $og->createImage(); $text = (new TextElement()) ->setText('OgImage') ->setFontSize(75) ->setFontColor('#ffffff') ->setFontPath('src/assets/fonts/BebasNeue-Regular.ttf') ->setBgOpacity(50) ->setMargin(50) ->setPosition('top', 'center'); $text2 = (new TextElement()) ->setText('Hello World!') ->setFontSize(50) ->setFontColor('#ffffff') ->setFontPath('src/assets/fonts/BebasNeue-Regular.ttf') ->setBgColor('#000000') ->setBgOpacity(50) ->setPosition(470, 'center'); $text3 = (new TextElement()) ->setText('Lorem ipsum dolor sit amet, consectetur adipiscing elit. ') ->setFontSize(25) ->setFontColor('#ffffff') ->setFontPath('src/assets/fonts/BebasNeue-Regular.ttf') ->setBgOpacity(50) ->setPosition(539, 'center'); $watermark = (new Watermark()) ->setWatermarkPath('src/assets/images/watermark.png') ->setSize(100) ->setMargin(10) ->setPosition('bottom', 'right'); $og->addWatermark($watermark); $og->addText($text); $og->addText($text2); $og->addText($text3); $og->render();
📦 Installation
composer require 53ny4/og-image
⚙️ Requirements
- PHP ^8.2
imagine/imagine(automatically installed)- supports only
GDdriver
🚀 Features
- Add styled text to your image (font, size, color, opacity, alignment)
- Add background overlays for text
- Automatic text wrapping and line height adjustment
- Place elements using top/center/bottom and left/center/right positions
- Add watermarks with position and opacity options
- Fit and scale background images to fill the canvas
🧱 Usage
require 'vendor/autoload.php'; use s3ny4\OgImage\OgImageGenerator; use s3ny4\OgImage\TextElement; use s3ny4\OgImage\Watermark; // Create generator instance $og = new OgImageGenerator(1200, 630); // Add background image $og->setBackgroundImage('path/to/background.jpg'); // Add text $text = (new TextElement()) ->setText('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam accumsan sed lacus venenatis eleifend. Aenean ipsum turpis, faucibus nec maximus sit amet, lobortis vel nisl. ') ->setPosition('center', 'center') ->setFontPath('src/assets/fonts/font.ttf') ->setFontSize(36) ->setFontColor('#ffffff') ->setBgOpacity(50) ->setBgColor('#ff0000'); $og->addText($text); // Add watermark $watermark = (new Watermark('src/assets/images/logo.png')) ->setPosition('top', 'center') ->setMargin(50) ->setSize(150) ->setOpacity(50); $og->addWatermark($watermark); // output image to the browser $og->render(); // or save to file // $og->render('og-image.png');
📝 License
This project is licensed under the MIT License. See the LICENSE file for details.
53ny4/og-image 适用场景与选型建议
53ny4/og-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 553 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「og」 「open graph」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 53ny4/og-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 53ny4/og-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 53ny4/og-image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Netgen Open Graph Bundle is an Ibexa Platform bundle that allows simple integration with Open Graph protocol.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
A tool for scraping URL resources (oEmbed, OpenGraph, Twitter cards, JSON-LD)
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Neo4j-PHP-Client is the most advanced PHP Client for Neo4j
统计信息
- 总下载量: 553
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-23
