psn / faker-image-provider
为 fakerPHP 库提供图像服务。
v1.0.2
2024-06-22 17:37 UTC
Requires
- php: >=8.2
- ext-imagick: *
- fakerphp/faker: ^1.23
Requires (Dev)
- pestphp/pest: ^2.34
- spatie/temporary-directory: ^2.2
- xrdebug/php: ^2.0
- xrdebug/xrdebug: ^2.0
This package is auto-updated.
Last update: 2024-09-22 18:12:20 UTC
README
FakerPHP 图像提供者
为 FakerPHP 库定制的图像提供者。
该包使用 LOREM PICSUM 生成 URL 和图像。
安装
composer require psn/faker-image-provider
用法
-
添加提供者
$faker = Faker\Factory::create(); $faker->addProvider(new Psn\FakerImageProvider\Image($faker));
-
生成 URL
// signature Image::imageUrl(int $witdth = 640, int $height = 480): string
// https://picsum.photos/640/480 $url = $faker->imageUrl(); // https://picsum.photos/1280/720 $url = $faker->imageUrl(width: 1280, height: 720);
-
生成图像
// signature Image::image( int $width = 640, int $height = 480, ?string $directory = null, ?string $extension = null ): string
// /tmp/faker_img_6672b731a5760.jpg $path = $faker->image(); // /home/user/test/faker_img_6672b731a5760.jpg $path = $faker->image(directory: '~/test'); // /tmp/faker_img_6672b731a5760.heic $path = $faker->image(extension: 'heic');