Elgg  Version master
LocalImage.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
10 class LocalImage extends Image {
11 
15  public static function image(
16  $dir = null,
17  $width = 640,
18  $height = 480,
19  $category = null,
20  $fullPath = true,
21  $randomize = true,
22  $word = null,
23  $gray = false,
24  $format = 'png'
25  ) {
26  $local_folder = elgg_get_config('seeder_local_image_folder');
27  if (empty($local_folder) || !is_dir($local_folder)) {
28  return parent::image($dir, $width, $height, $category, $fullPath, $randomize, $word, $format);
29  }
30 
31  $files = [];
32 
33  // read files in folder
34  $dir = new \DirectoryIterator($local_folder);
35  /* @var $file \SplFileInfo */
36  foreach ($dir as $file) {
37  if (!$file->isFile()) {
38  continue;
39  }
40 
41  $files[] = $file->getRealPath();
42  }
43 
44  if (empty($files)) {
45  return parent::image($dir, $width, $height, $category, $fullPath, $randomize, $word, $format);
46  }
47 
48  // return random file
49  $key = array_rand($files);
50 
51  return $files[$key];
52  }
53 }
Provide images from a local folder for seeding.
Definition: LocalImage.php:10
$format
Definition: date.php:37
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
static image($dir=null, $width=640, $height=480, $category=null, $fullPath=true, $randomize=true, $word=null, $gray=false, $format= 'png')
{}
Definition: LocalImage.php:15
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44