fractal512/og-image 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

fractal512/og-image

Composer 安装命令:

composer require fractal512/og-image

包简介

Open Graph image generator based on Intervention Image - PHP image processing library

README 文档

README

Open Graph image generator based on Intervention Image - PHP image processing library.

OG image preview

Packagist Version Tests Packagist PHP Version Support GitHub License

Features:

  • Image generation with fully customizable text, logo, background and overlay
  • Background image effects, like a blur, grayscale, etc.
  • Custom fading overlay over background
  • Easy switch between GD and Imagick drivers

Requirements

Installation

The package can be installed via composer:

composer require fractal512/og-image

For the Laravel framework use fractal512/laravel-og-image package.

Usage

Use make() method to create Open Graph image, overriding default settings with needed in $config array before:

<?php

use Fractal512\OpenGraphImage\OpenGraphImage;

require __DIR__ . '/vendor/autoload.php';

$config = [
    'logo_path' => __DIR__ . '/path/to/logo.png',
    'background_path' => __DIR__ . '/path/to/background.png',
    // override other default settings from the configuration (see below all list)
];

$text = 'Text to be printed on the Open Graph Image';
$output = __DIR__ . '/generated-image.png';

$image = new OpenGraphImage($config);
$image->make($text)->save($output);

Custom background can be passed as a second parameter in make() method:

// ...
$background = __DIR__ . '/background-image.png';
$image = new OpenGraphImage($config);
$image->make($text, $background)->save($output);

Output image format

The format of the output image is autodetected from the path passed to the save() method:

// ...
// supported output image formats: png, jpg, webp (with imagick driver only)
$output = __DIR__ . '/generated-image.png';
$image = new OpenGraphImage($config);
$result = $image->make($text)->save($output);
// $result is boolean true or false

Configuration

Built-in default configuration settings list:

$config = [
    /*
    |--------------------------------------------------------------------------
    | Image Processing Driver
    |--------------------------------------------------------------------------
    |
    | Supported: "gd" or "imagick"
    |
    */
    'driver' => 'gd',

    /*
    |--------------------------------------------------------------------------
    | Image Width
    |--------------------------------------------------------------------------
    |
    */
    'image_width' => 1200,

    /*
    |--------------------------------------------------------------------------
    | Image Height
    |--------------------------------------------------------------------------
    |
    */
    'image_height' => 630,

    /*
    |--------------------------------------------------------------------------
    | Image Background Color
    |--------------------------------------------------------------------------
    |
    */
    'background_color' => '#444444',

    /*
    |--------------------------------------------------------------------------
    | Background Image Path
    |--------------------------------------------------------------------------
    |
    | Path to the image used for background.
    |
    | Supported: "absolute/path/to/your/background/image.png", null
    |
    */
    'background_path' => null,

    /*
    |--------------------------------------------------------------------------
    | Background Fill
    |--------------------------------------------------------------------------
    |
    | Scale the image to fill the background.
    |
    */
    'background_fill' => true,

    /*
    |--------------------------------------------------------------------------
    | Background Image Effects
    |--------------------------------------------------------------------------
    |
    | An associative array of image effects, where an element's key is
    | the effect method's name in the Intervention library.
    | Different methods accept different numbers of arguments.
    | If no arguments, set null as an element's value, if more than one
    | argument needs to be passed, wrap them into an array.
    | Read more: https://image.intervention.io/v3/modifying/effects
    |
    | Available effects are:
    |     "brightness" - 1 argument, integer in range -100..100
    |     "contrast" - 1 argument, integer in range -100..100
    |     "gamma" - 1 argument, float
    |     "colorize" - 3 arguments, all integers in range -100..100
    |     "greyscale" - no arguments, set null
    |     "flop" - no arguments, set null
    |     "flip" - no arguments, set null
    |     "blur" - 1 argument, integer in range 0..100
    |     "sharpen" - 1 argument, integer in range 0..100
    |     "invert" - no arguments, set null
    |     "pixelate" - 1 argument, integer
    |     "reduceColors" - 2 arguments, integer, string
    |
    */
    'background_effects' => [],

    /*
    |--------------------------------------------------------------------------
    | Overlay Color
    |--------------------------------------------------------------------------
    |
    */
    'overlay_color' => '#000000',

    /*
    |--------------------------------------------------------------------------
    | Overlay Transparency Alpha Channel
    |--------------------------------------------------------------------------
    |
    | Supported: float
    |
    */
    'overlay_alpha' => 0.35,

    /*
    |--------------------------------------------------------------------------
    | Logo Image Path
    |--------------------------------------------------------------------------
    |
    | Path to the image used for the logo.
    |
    | Supported: "absolute/path/to/your/logo/image.png", null
    |
    */
    'logo_path' => null,

    /*
    |--------------------------------------------------------------------------
    | Logo Position
    |--------------------------------------------------------------------------
    |
    | Supported: "top-left", "top", "top-right", "left", "center", "right",
    | "bottom-left", "bottom", "bottom-right"
    |
    */
    'logo_position' => 'bottom-right',

    /*
    |--------------------------------------------------------------------------
    | Logo Offset on X-axis
    |--------------------------------------------------------------------------
    |
    */
    'logo_pos_x' => 100,

    /*
    |--------------------------------------------------------------------------
    | Logo Offset on Y-axis
    |--------------------------------------------------------------------------
    |
    */
    'logo_pos_y' => 50,

    /*
    |--------------------------------------------------------------------------
    | Logo Opacity
    |--------------------------------------------------------------------------
    |
    */
    'logo_opacity' => 100,

    /*
    |--------------------------------------------------------------------------
    | Text X Position
    |--------------------------------------------------------------------------
    |
    | Coordinate on X-axis defining the base point of the first character.
    |
    */
    'text_pos_x' => 600,

    /*
    |--------------------------------------------------------------------------
    | Text Y Position
    |--------------------------------------------------------------------------
    |
    | Coordinate on Y-axis defining the base point of the first character.
    |
    */
    'text_pos_y' => 315,

    /*
    |--------------------------------------------------------------------------
    | Text Horizontal Alignment
    |--------------------------------------------------------------------------
    |
    | Supported: "left", "center", "right"
    |
    */
    'text_horizontal_align' => 'center',

    /*
    |--------------------------------------------------------------------------
    | Text Vertical Alignment
    |--------------------------------------------------------------------------
    |
    | Supported: "top", "middle", "bottom"
    |
    */
    'text_vertical_align' => 'middle',

    /*
    |--------------------------------------------------------------------------
    | Text Wrap Width
    |--------------------------------------------------------------------------
    |
    */
    'text_wrap_width' => 1000,

    /*
    |--------------------------------------------------------------------------
    | Line Height
    |--------------------------------------------------------------------------
    |
    | Supported: float
    |
    */
    'text_line_height' => 1.5,

    /*
    |--------------------------------------------------------------------------
    | Text Color
    |--------------------------------------------------------------------------
    |
    */
    'text_color' => '#ffffff',

    /*
    |--------------------------------------------------------------------------
    | Text Font Size
    |--------------------------------------------------------------------------
    |
    */
    'text_font_size' => 48,

    /*
    |--------------------------------------------------------------------------
    | Font Path
    |--------------------------------------------------------------------------
    |
    | If null, preset font (Roboto Regular) will be used.
    |
    | Supported: "absolute/path/to/your/font.ttf", null
    |
    */
    'text_font_path' => null,
];

Credits

License

The MIT License (MIT). Please see License File for more information.

fractal512/og-image 适用场景与选型建议

fractal512/og-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「open graph」 「og-image」 「twitter image」 「vk image」 「facebook image」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fractal512/og-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fractal512/og-image 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-30