定制 teariot/faker-fillthis 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

teariot/faker-fillthis

最新稳定版本:1.2.2

Composer 安装命令:

composer require teariot/faker-fillthis

包简介

A Laravel Faker provider for generating placeholder images via the fillthis.io service.

README 文档

README

FakerFillThis is a custom Faker provider for generating placeholder image URLs and downloading images from fillthis.io. This provider conforms to the Laravel Faker interface for imageUrl, image, and url methods.

Installation

Install via Composer:

  composer require teariot/faker-fillthis

Usage

Add the provider to your Faker instance:

use Faker\Factory;
use TeaRiot\FakerFillThis\Faker\Provider\FillThisImage;

$faker = Factory::create();
$faker->addProvider(new FillThisImage($faker));

Generating an Image URL

  • Default Image: Returns the default endpoint.
    echo $faker->imageUrl(0, 0);
  • Custom Dimensions: For a 500x500 image.
    echo $faker->imageUrl(500, 500, null, false, null, false, "png");
  • With Random Word: Appends a random word to the text parameter.
    echo $faker->imageUrl(800, 600, null, true, null, false, "png");
  • Category-based Image: When specifying a category (e.g., "fashion" or "all"), the library generates a URL with a seed that directly points to an image from that category. Note that in this mode, the width and height parameters are ignored. This approach is implemented for improved performance by avoiding the need to resize images.
    echo $faker->imageUrl(0, 0, "fashion", false, null, false, "png");

Generating a Video URL

When the type is set to "video", the URL will include a .mp4 extension for clear identification:

echo $faker->url('video');

Downloading an Image

Download an image to a specified directory (or system temporary directory by default):

$imagePath = $faker->image(__DIR__, 800, 600, null, true, true, "TestImage", false, "png");
if ($imagePath !== false) {
    echo "Image downloaded at: " . $imagePath;
} else {
    echo "Error downloading image.";
}

API Reference

  • imageUrl
    imageUrl(
        int $width = 640,
        int $height = 480,
        ?string $category = null,
        bool $randomize = true,
        ?string $word = null,
        bool $gray = false,
        string $format = 'png'
    ): string
  • url
    url(?string $type = null): string
  • image
    image(
        ?string $dir = null,
        int $width = 640,
        int $height = 480,
        ?string $category = null,
        bool $fullPath = true,
        bool $randomize = true,
        ?string $word = null,
        bool $gray = false,
        string $format = 'png'
    ): string|false

Categories

Note: The list of categories is deprecated. To obtain the complete list of categories, call the API at https://fillthis.io/categories.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-24