PHP code example of bradietilley / faker-imagez

1. Go to this page and download the library: Download bradietilley/faker-imagez library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bradietilley / faker-imagez example snippets


class Something extends Imagez
{
    public static function basePath(): string
    {
        return '/path/to/images';
    }
}

imagez()->path();                             // string: /path/to/pics/image_0037.jpg
imagez()->path();                             // string: /path/to/pics/image_0101.jpg

imagez()->contents();                         // string: <contents of /path/to/pics/image_0087.jpg>
imagez()->contents();                         // string: <contents of /path/to/pics/image_0120.jpg>

imagez()->fileinfo();                         // \SplInfo: <fileinfo of /path/to/pics/image_0042.jpg>
imagez()->fileinfo();                         // \SplInfo: <fileinfo of /path/to/pics/image_0099.jpg>

imagez()->get(24);                            // string: /path/to/pics/image_0024.jpg
imagez()->get(43);                            // string: /path/to/pics/image_0043.jpg

$min = 1;
$max = catz()->count();

$image = catz()->get(mt_rand($min, $max));  // string: /path/to/pics/image_XXXX.jpg

imagez()->iterate();                          // Iterates to the next image

imagez()->getCurrentImagePath();              // string: /path/to/pics/image_0046.jpeg                 (won't iterate)
imagez()->getCurrentImagePath();              // string: /path/to/pics/image_0046.jpeg                 (won't iterate)
imagez()->getCurrentImageContents();          // string: <contents of /path/to/pics/image_0046.jpeg>   (won't iterate)
imagez()->getCurrentImageFileinfo();          // \SplFileInfo: /path/to/pics/image_0046.jpeg           (won't iterate)

imagez()->all();                              // array: <path1, path2, ..., path118, path119, path120>

imagez()->path();                             // this iterates the pool, popping the last path from the pool
imagez()->pool();                             // array: <path1, path2, ..., path118, path119>         (pool contains one less now)

imagez()->path();                             // this iterates the pool, popping the last path from the pool
imagez()->pool();                             // array: <path1, path2, ..., path118>                  (pool contains one less now)

foreach (range(1, 100) as $i) {
    imagez()->path();                         // iterates 100 images
}

imagez()->loadWhenEmpty();                    // Won't do anything here as there's still images in the pool.
imagez()->load();                             // Will reload the pool of images to be the full collection of image images. 

$all = imagez()->all();
unset($all[23452]);                           // Say you don't like this one

imagez()->replaceAll($all);

imagez()->path();                             // Will never 

$generator = catz()->combine(dogz(), foodz());
// or
$generator = CombineImagez::make(catz(), dogz(), foodz());

// Then interact with it as you otherwise would:
$generator->path();                           // path to a dog image
$generator->path();                           // path to a cat image
$generator->path();                           // path to a food image