MediaWiki
1.28.0
|
RandomImageGenerator: does what it says on the tin. More...
Public Member Functions | |
static | __construct ($options=[]) |
getImageSpec () | |
Generate data representing an image of random size (within limits), consisting of randomly colored and sized upward pointing triangles against a random background color. More... | |
getImageWriteMethod ($format) | |
Figure out how we write images. More... | |
getRandomColor () | |
Generate a string of random colors for ImageMagick or SVG, like "rgb(12, 37, 98)". More... | |
writeImages ($number, $format= 'jpg', $dir=null) | |
Writes random images with random filenames to disk in the directory you specify, or current working directory. More... | |
writeImageWithApi ($spec, $format, $filename) | |
Based on an image specification, write such an image to disk, using Imagick PHP extension. More... | |
writeImageWithCommandLine ($spec, $format, $filename) | |
Based on an image specification, write such an image to disk, using the command line ImageMagick program ('convert'). More... | |
writeSvg ($spec, $format, $filename) | |
Based on image specification, write a very simple SVG file to disk. More... | |
Static Public Member Functions | |
static | shapePointsToString ($shape) |
Given [ [ 'x' => 10, 'y' => 20 ], [ 'x' => 30, y=> 5 ] ] returns "10,20 30,5" Useful for SVG and imagemagick command line arguments. More... | |
Private Member Functions | |
getRandomFilenames ($number, $extension= 'jpg', $dir=null) | |
Return a number of randomly-generated filenames Each filename uses two words randomly drawn from the dictionary, like elephantine_spatula.jpg. More... | |
getRandomLines ($number_desired) | |
Return N random lines from a file. More... | |
getRandomWordPairs ($number) | |
Get an array of random pairs of random words, like [ [ 'foo', 'bar' ], [ 'quux', 'baz' ] ];. More... | |
Static Private Member Functions | |
static | matrixMultiply2x2 ($matrix, $x, $y) |
Given a matrix and a pair of images, return new position. More... | |
static | rotateImageSpec (&$spec, $matrix) |
Given an image specification, produce rotated version This is used when simulating a rotated image capture with Exif orientation. More... | |
Private Attributes | |
$dictionaryFile | |
$maxHeight = 800 | |
$maxWidth = 800 | |
$minHeight = 400 | |
$minWidth = 400 | |
$shapesToDraw = 5 | |
Static Private Attributes | |
static | $orientations |
Orientations: 0th row, 0th column, Exif orientation code, rotation 2x2 matrix that is opposite of orientation. More... | |
RandomImageGenerator: does what it says on the tin.
Can fetch a random image, or also write a number of them to disk with random filenames.
Definition at line 30 of file RandomImageGenerator.php.
static RandomImageGenerator::__construct | ( | $options = [] | ) |
Definition at line 72 of file RandomImageGenerator.php.
References $dictionaryFile, $options, $property, and(), and as.
RandomImageGenerator::getImageSpec | ( | ) |
Generate data representing an image of random size (within limits), consisting of randomly colored and sized upward pointing triangles against a random background color.
(This data is used in the writeImage* methods).
Definition at line 183 of file RandomImageGenerator.php.
References $shapesToDraw, and getRandomColor().
Referenced by writeImages().
RandomImageGenerator::getImageWriteMethod | ( | $format | ) |
Figure out how we write images.
This is a factor of both format and the local system
string | $format | (a typical extension like 'svg', 'jpg', etc.) |
Exception |
Definition at line 129 of file RandomImageGenerator.php.
References $wgExiv2Command, $wgImageMagickConvertCommand, $wgUseImageMagick, and global.
Referenced by writeImages().
RandomImageGenerator::getRandomColor | ( | ) |
Generate a string of random colors for ImageMagick or SVG, like "rgb(12, 37, 98)".
Definition at line 422 of file RandomImageGenerator.php.
Referenced by getImageSpec().
|
private |
Return a number of randomly-generated filenames Each filename uses two words randomly drawn from the dictionary, like elephantine_spatula.jpg.
int | $number | Number of filenames to generate |
string | $extension | Optional, defaults to 'jpg' |
string | $dir | Optional, defaults to current working directory |
Definition at line 158 of file RandomImageGenerator.php.
References $dir, as, and getRandomWordPairs().
Referenced by writeImages().
|
private |
Return N random lines from a file.
Will throw exception if the file could not be read or if it had fewer lines than requested.
int | $number_desired | Number of lines desired |
Exception |
Definition at line 460 of file RandomImageGenerator.php.
References $dictionaryFile, $line, and $lines.
Referenced by getRandomWordPairs().
|
private |
Get an array of random pairs of random words, like [ [ 'foo', 'bar' ], [ 'quux', 'baz' ] ];.
int | $number | Number of pairs |
Definition at line 438 of file RandomImageGenerator.php.
References $count, $lines, and getRandomLines().
Referenced by getRandomFilenames().
|
staticprivate |
Given a matrix and a pair of images, return new position.
array | $matrix | 2x2 rotation matrix |
int | $x | The x-coordinate number |
int | $y | The y-coordinate number |
Definition at line 373 of file RandomImageGenerator.php.
|
staticprivate |
Given an image specification, produce rotated version This is used when simulating a rotated image capture with Exif orientation.
array | $spec | Returned by getImageSpec |
array | $matrix | 2x2 transformation matrix |
Definition at line 334 of file RandomImageGenerator.php.
References as.
|
static |
Given [ [ 'x' => 10, 'y' => 20 ], [ 'x' => 30, y=> 5 ] ] returns "10,20 30,5" Useful for SVG and imagemagick command line arguments.
array | $shape | Array of arrays, each array containing x & y keys mapped to numeric values |
Definition at line 227 of file RandomImageGenerator.php.
RandomImageGenerator::writeImages | ( | $number, | |
$format = 'jpg' , |
|||
$dir = null |
|||
) |
Writes random images with random filenames to disk in the directory you specify, or current working directory.
int | $number | Number of filenames to write |
string | $format | Optional, must be understood by ImageMagick, such as 'jpg' or 'gif' |
string | $dir | Directory, optional (will default to current working directory) |
Definition at line 111 of file RandomImageGenerator.php.
References $dir, as, getImageSpec(), getImageWriteMethod(), and getRandomFilenames().
RandomImageGenerator::writeImageWithApi | ( | $spec, | |
$format, | |||
$filename | |||
) |
Based on an image specification, write such an image to disk, using Imagick PHP extension.
array | $spec | Spec describing background and circles to draw |
string | $format | File format to write |
string | $filename | Filename to write to |
Definition at line 275 of file RandomImageGenerator.php.
References $image, $retval, $wgExiv2Command, as, global, print, wfEscapeShellArg(), and wfShellExec().
RandomImageGenerator::writeImageWithCommandLine | ( | $spec, | |
$format, | |||
$filename | |||
) |
Based on an image specification, write such an image to disk, using the command line ImageMagick program ('convert').
Sample command line: $ convert -size 100x60 xc:rgb(90,87,45) \ -draw 'fill rgb(12,34,56) polygon 41,39 44,57 50,57 41,39' \ -draw 'fill rgb(99,123,231) circle 59,39 56,57' \ -draw 'fill rgb(240,12,32) circle 50,21 50,3' filename.png
array | $spec | Spec describing background and shapes to draw |
string | $format | File format to write (unused by this method but kept so it has the same signature as writeImageWithApi). |
string | $filename | Filename to write to |
Definition at line 397 of file RandomImageGenerator.php.
References $args, $command, $retval, $wgImageMagickConvertCommand, as, global, wfEscapeShellArg(), and wfShellExec().
RandomImageGenerator::writeSvg | ( | $spec, | |
$format, | |||
$filename | |||
) |
Based on image specification, write a very simple SVG file to disk.
Ignores the background spec because transparency is cool. :)
array | $spec | Spec describing background and shapes to draw |
string | $format | File format to write (which is obviously always svg here) |
string | $filename | Filename to write to |
Exception |
Definition at line 246 of file RandomImageGenerator.php.
References as.
|
private |
Definition at line 31 of file RandomImageGenerator.php.
Referenced by __construct(), and getRandomLines().
|
private |
Definition at line 35 of file RandomImageGenerator.php.
|
private |
Definition at line 33 of file RandomImageGenerator.php.
|
private |
Definition at line 34 of file RandomImageGenerator.php.
|
private |
Definition at line 32 of file RandomImageGenerator.php.
|
staticprivate |
Orientations: 0th row, 0th column, Exif orientation code, rotation 2x2 matrix that is opposite of orientation.
N.b. we do not handle the 'flipped' orientations, which is why there is no entry for 2, 4, 5, or 7. Those seem to be rare in real images anyway (we also would need a non-symmetric shape for the images to test those, like a letter F).
Definition at line 45 of file RandomImageGenerator.php.
|
private |
Definition at line 36 of file RandomImageGenerator.php.
Referenced by getImageSpec().