packitifotech/laragdads

使用GD图像库创建广告横幅

dev-main 2023-07-16 15:51 UTC

This package is auto-updated.

Last update: 2024-09-16 18:28:08 UTC


README

一个用于从图像创建广告横幅的PHP类。使用PHP和GD,Imagick或Gmagick,color-thief-php库来实现。

example image

要求

  • PHP >= 7.2 或 >= PHP 8.0
  • Fileinfo扩展
  • 一个或多个PHP图像处理扩展
    • GD >= 2.0
    • Imagick >= 2.0(但CMYK图像需 >= 3.0)
    • Gmagick >= 1.0
  • 支持JPEG,PNG。

如何使用

通过Composer安装

推荐通过Composer安装Laravel Gd Ads

composer require packitifotech/laragdads

从图像中获取主色

use Packitifotech\Laragdads\Laragdads;
$image1 = public_path('fruits.jpg');
$image2 = public_path('orange.jpg');
$fontPath = public_path('FjallaOne-Regular.ttf');
$text = "The tree that bears the most fruit gets the most attention. Allow the fruit to fall and rot";
$gdImage = Laragdads::createHorizontalAdsBanner(fImagepath: $image1, sImagePath:$image2, fontPath:$fontPath, text:$text, resizeWidth:null, resizeHeight:null);
Laragdads::saveAdsBannerPng($horizontalAds, Storage::path('public/ads'));

$image1$image2变量必须包含服务器上图像的绝对路径。$fontPath变量必须包含服务器上图像的绝对路径。

Laragdads::saveAdsBannerPng(gdImage: $gdImage, storagePath: $storagePath)

您可以通过调用saveAdsBannerPng方法将横幅GD实例图像保存为png

致谢

作者

由Tushar Sawant itinfotech.in

基于Lokesh Dhakar的出色工作 itinfotech.in

感谢