承接 53ny4/og-image 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

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 GD driver

🚀 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 53ny4/og-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 553
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-23