Code Monkey home page Code Monkey logo

faker-images's Introduction

Faker Images Provider

codecov

picsum.photos provider for Faker.

lorem.space provider for Faker.

fakeimg provider for Faker.

Install

Install the Providers by adding mmo/faker-images to your composer.json or from CLI:

$ composer require --dev mmo/faker-images

Usage

<?php

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

$faker = Faker\Factory::create();
$faker->addProvider(new \Mmo\Faker\PicsumProvider($faker));
$faker->addProvider(new \Mmo\Faker\LoremSpaceProvider($faker));
$faker->addProvider(new \Mmo\Faker\FakeimgProvider($faker));

// picsum
// size
$url = $faker->picsumUrl(); // https://picsum.photos/640/480?random=24398
$url = $faker->picsumUrl(400, 400); // https://picsum.photos/400/400?random=23446

// static random
$url = $faker->picsumStaticRandomUrl(400, 400); // https://picsum.photos/seed/5efe7fec1bd11/400/400

// download image to tmp dir
$path = $faker->picsum(null, 400, 400, true); // /tmp/72c04225dd87efc261d29d3a050aa9b6.jpg

// Signature
// picsumUrl($width = 640, $height = 480, $id = null, $randomize = true, $gray = false, $blur = null, $static = false, $imageExtension = null)
// picsumStaticRandomUrl($width = 640, $height = 480, $gray = false, $blur = null, $imageExtension)
// picsum($dir = null, $width = 640, $height = 480, $fullPath = true, $id = null, $randomize = true, $gray = false, $blur = null, $imageExtension)

// lorem space
// you can use a self owned service, if there are problems with default one
// LoremSpaceProvider::setApiUrl('https://my-self-owned-lorem-space-service.example.com/image/');
$url = $faker->loremSpaceUrl(\Mmo\Faker\LoremSpaceProvider::CATEGORY_FACE); // https://api.lorem.space/image/face?w=640&h=480
// download image to tmp dir
$path = $faker->loremSpace(\Mmo\Faker\LoremSpaceProvider::CATEGORY_FACE); // /tmp/fd3646c544a9a46bd16d1d097e737ee4.jpg

// Signature
// loremSpaceUrl($category, $width = 640, $height = 480)
// loremSpace($category, $dir = null, $width = 640, $height = 480, $fullPath = true)

// Fakeimg
$url = $faker->fakeImgUrl(); // https://fakeimg.pl/640x480/CCCCCC/939393
// if you use PHP8+ you can use named argument and use helper function to create color
//$url = $faker->fakeImgUrl(backgroundColor: \Mmo\Faker\FakeimgUtils::createColor(255, 0, 0));
// download image to tmp dir
$path = $faker->fakeImg(); // /tmp/9aa6c1c7e4bc1901084997b0efa44f13.png

// Signature
// fakeImgUrl($width = 640, $height = 480, $text = '', array $backgroundColor = [], array $fontColor = [], $retina = false)
// fakeImg($dir = null, $width = 640, $height = 480, $fullPath = true, $text = '', array $backgroundColor = [], array $fontColor = [], $retina = false)

faker-images's People

Contributors

h3xexe avatar kostin avatar morawskim avatar nella17 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

faker-images's Issues

Advanced Usage

This is an awesome package. I have a suggestion.
There is a section called advanced usage in picsum website. for example, my need was to get the exact image URL with the jpg extension. I think it will be good for others. Thanks
image

`PicsumProvider` no longer working?

My code was:

$tempImagePath = $faker->picsum(null, $width, $height, imageExtension: $iconType == 'jpeg' ? 'jpg' : $iconType);

and was working for quite some time.

However, it now returns empty string instead path where file was downloaded.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.