承接 aleex1848/collage 相关项目开发

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

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

aleex1848/collage

Composer 安装命令:

composer require aleex1848/collage

包简介

Generate Image Collage with Laravel

README 文档

README

Collage Cover Image

GitHub License Latest Version on Packagist GitHub Tests Action Status Total Downloads

Create Image Collage with ease now with PHP. This package uses intervention/image package to leverage image manipulation.

Using this package is very easy and creating Beautiful Collages are not tough anymore.

NOTE: Currently this package only supports 4 images. You can write your own generator to add 5 if you like.

📦 Installation

This is a composer package. So just run the below composer command inside your project directory to get it installed.

composer require tzsk/collage

⚙️ Configure

If you are using this package outside laravel then you don't need to do this step.

config/app.php

This package supports Package Auto-Discovery. And the latest version only supports Laravel >= 7.x

If you want to use any other driver besides 'gd' then you have to publish the configuration file:

php artisan collage:publish

You will then have a file in your config directory: config/collage.php

If you are using 'imagick' then you can change it.

🔥 Usage

First you need to have a set of images to make collage of. This package can except many kinds of Targets.

$images = [
    // List of images
    'images/some-image.jpg',
];

There are other kinds of image targets supported:

$images = [
    // 1. File Contents
    file_get_contents('some/image/path/or/url'),

    // 2. Direct URLs
    'https://some/image/url',

    // 3. Absolute & Relative Path
    '/some/image/somewhere/on/disk',

    // 4. Intervention\Image\Image Object
    ImageManagerStatic::make('...'),
    // It's Intervention\Image\ImageManagerStatic

    // 5. Or if you are Using Laravel
    Image::make('...'),
    // It's Intervention\Image\Facades\Image
];

Depending upon the number of images in the array this package will automatically use the right Generator.

🌐 Examples Outside Laravel

Firstly, use the Class Namespace at the top.

use Tzsk\Collage\MakeCollage;

$collage = new MakeCollage($driver); // Default: 'gd'

The Driver is either 'gd' or 'imagick'. Depending upon which library you are using with PHP. You can customize that. The default is 'gd'.

Create collage with 1 Image

Supported, yes.

$image = $collage->make(400, 400)->from($images);

// Add Padding:
$image = $collage->make(400, 400)->padding(10)->from($images);

// Add Background Color:
$image = $collage->make(400, 400)->padding(10)->background('#000')->from($images);

Create collage with 2 images

$image = $collage->make(400, 400)->from($images); // Default Alignment: vertical

// Change Alignment:
$image = $collage->make(400, 400)->from($images, function($alignment) {
    $alignment->vertical(); // Default, no need to have the Closure at all.
    // OR...
    $alignment->horizontal();
});

You can also add padding() and background() here.

Create collage with 3 images

$image = $collage->make(400, 400)->from($images); // Default Alignment: twoTopOneBottom

// Change Alignment:
$image = $collage->make(400, 400)->from($images, function($alignment) {
    $alignment->twoTopOneBottom(); // Default, no need to have the Closure at all.
    // OR...
    $alignment->oneTopTwoBottom();
    // OR...
    $alignment->oneLeftTwoRight();
    // OR...
    $alignment->twoLeftOneRight();
    // OR...
    $alignment->vertical();
    // OR...
    $alignment->horizontal();
});

You can also add padding() and background() here.

Create collage with 4 images

$image = $collage->make(400, 400)->from($images); // Default Alignment: grid

// Change Alignment:
$image = $collage->make(400, 400)->from($images, function($alignment) {
    $alignment->grid(); // Default, no need to have the Closure at all.
    // OR...
    $alignment->vertical();
    // OR...
    $alignment->horizontal();
});

You can also add padding() and background() here.

😍 Examples in Laravel

In laravel you already have the Alias for the Collage Maker

use Tzsk\Collage\Facade\Collage;

$image = Collage::make(400, 400)->from($images);

The rest of the Features are same as when using in normal php.

Create collage with 1 Image

$image = Collage::make(400, 400)->from($images);

// Add Padding:
$image = Collage::make(400, 400)->padding(10)->from($images);

// Add Background Color:
$image = Collage::make(400, 400)->padding(10)->background('#000')->from($images);

Create collage with 2 images

$image = Collage::make(400, 400)->from($images); // Default Alignment: vertical

// Change Alignment:
$image = Collage::make(400, 400)->from($images, function($alignment) {
    $alignment->vertical(); // Default, no need to have the Closure at all.
    // OR...
    $alignment->horizontal();
});

You can also add padding() and background() here.

Create collage with 3 images

$image = Collage::make(400, 400)->from($images); // Default Alignment: twoTopOneBottom

// Change Alignment:
$image = Collage::make(400, 400)->from($images, function($alignment) {
    $alignment->twoTopOneBottom(); // Default, no need to have the Closure at all.
    // OR...
    $alignment->oneTopTwoBottom();
    // OR...
    $alignment->oneLeftTwoRight();
    // OR...
    $alignment->twoLeftOneRight();
    // OR...
    $alignment->vertical();
    // OR...
    $alignment->horizontal();
});

You can also add padding() and background() here.

Create collage with 4 images

$image = Collage::make(400, 400)->from($images); // Default Alignment: grid

// Change Alignment:
$image = Collage::make(400, 400)->from($images, function($alignment) {
    $alignment->grid(); // Default, no need to have the Closure at all.
    // OR...
    $alignment->vertical();
    // OR...
    $alignment->horizontal();
});

You can also add padding() and background() here.

🏆 Return Value

The reaturned $image is the instance of Intervention\Image\Image object.

You can do multiple things with it.

  • You can save the final collage.
  • You can just use it as a plain response.
  • You can crop/resize/colorize and more.

Read more about what you can do in the Official Documentation.

🔌 Create Custom Generators

Creating a generator is very easy. Create a class that extends the abstract class: Tzsk\Collage\Contracts\CollageGenerator.

Example:

use Tzsk\Collage\Contracts\CollageGenerator;

class FiveImage extends CollageGenerator
{
    /**
     * @param Closure $closure
     * @return \Intervention\Image\Image
     */
    public function create($closure = null)
    {
        // Your code to generate the Intervention\Image\Image object
    }
}

NOTE: Take a look at src/Contracts/CollageGenerator.php for details about all the things you have access to in the generator class. Also, if you need a reference consider looking into: src/Generators/FourImage.php.

Extend outside laravel

$image = $collage->with([5 => Your\Class\Namespace\FiveImage::class]);
// Here the key is the number of file your generator accepts.
// After this you can continue chaining methods like ->padding()->from() as usual.

You can also override existing generators. Let's say you want to have the FourImage generator to behave differently. You can make your own MyFourImage class and add it.

$image = $collage->with([4 => Your\Class\Namespace\MyFourImage::class]);
// It will replace the existing Generator with your own.
// After this you can continue chaining methods like ->padding()->from() as usual.

Extend in laravel

$image = Collage::with([5 => Your\Class\Namespace\FiveImage::class]);
// Here the key is the number of file your generator accepts.
// After this you can continue chaining methods like ->padding()->from() as usual.

You can also override existing generators. Let's say you want to have the FourImage generator to behave differently. You can make your own MyFourImage class and add it.

$image = Collage::with([4 => Your\Class\Namespace\MyFourImage::class]);
// It will replace the existing Generator with your own.
// After this you can continue chaining methods like ->padding()->from() as usual.

You can also do this from the config/collage.php config file.

There is a generators array which is currently empty. You can add your own generators there like below to Replace or add new generators.

'generators' => [
    // It will replace the current FourImage generator.
    4 => Your\Class\Namespace\MyFourImage::class,

    // It will add a new generator.
    5 => Your\Class\Namespace\FiveImage::class,
]

🔬 Testing

composer test

📅 Changelog

Please see CHANGELOG for more information on what has changed recently.

❤️ Contributing

Please see CONTRIBUTING for details.

🔒 Security

If you discover any security related issues, please email mailtokmahmed@gmail.com instead of using the issue tracker.

👑 Credits

👮‍♂️ License

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

aleex1848/collage 适用场景与选型建议

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

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

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

围绕 aleex1848/collage 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-14