MediaWiki  1.23.1
RandomImageGenerator Class Reference

RandomImageGenerator: does what it says on the tin. More...

Public Member Functions

 __construct ( $options=array())
 
 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). 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 array( array('x' => 10, 'y' => 20), array( '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 array( array( 'foo', 'bar' ), array( '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 n.b. More...
 

Detailed Description

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 27 of file RandomImageGenerator.php.

Constructor & Destructor Documentation

◆ __construct()

RandomImageGenerator::__construct (   $options = array())

Definition at line 69 of file RandomImageGenerator.php.

References $dictionaryFile, $options, $property, array(), and as.

Member Function Documentation

◆ getImageSpec()

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).

Returns
{Mixed}

Definition at line 170 of file RandomImageGenerator.php.

References $shapesToDraw, array(), and getRandomColor().

Referenced by writeImages().

◆ getImageWriteMethod()

RandomImageGenerator::getImageWriteMethod (   $format)

Figure out how we write images.

This is a factor of both format and the local system

Parameters
string$format(a typical extension like 'svg', 'jpg', etc.)
Exceptions
Exception
Returns
string

Definition at line 122 of file RandomImageGenerator.php.

References global.

Referenced by writeImages().

◆ getRandomColor()

RandomImageGenerator::getRandomColor ( )

Generate a string of random colors for ImageMagick or SVG, like "rgb(12, 37, 98)".

Returns
string

Definition at line 403 of file RandomImageGenerator.php.

References array().

Referenced by getImageSpec().

◆ getRandomFilenames()

RandomImageGenerator::getRandomFilenames (   $number,
  $extension = 'jpg',
  $dir = null 
)
private

Return a number of randomly-generated filenames Each filename uses two words randomly drawn from the dictionary, like elephantine_spatula.jpg.

Parameters
int$numberNumber of filenames to generate
string$extensionOptional, defaults to 'jpg'
string$dirOptional, defaults to current working directory
Returns
array Array of filenames

Definition at line 147 of file RandomImageGenerator.php.

References $dir, array(), as, and getRandomWordPairs().

Referenced by writeImages().

◆ getRandomLines()

RandomImageGenerator::getRandomLines (   $number_desired)
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.

Parameters
int$number_desirednumber of lines desired
Exceptions
Exception
Returns
array of exactly n elements, drawn randomly from lines the file

Definition at line 440 of file RandomImageGenerator.php.

References $dictionaryFile, $line, $lines, and array().

Referenced by getRandomWordPairs().

◆ getRandomWordPairs()

RandomImageGenerator::getRandomWordPairs (   $number)
private

Get an array of random pairs of random words, like array( array( 'foo', 'bar' ), array( 'quux', 'baz' ) );.

Parameters
int$numberNumber of pairs
Returns
array two-element arrays

Definition at line 418 of file RandomImageGenerator.php.

References $count, $lines, array(), and getRandomLines().

Referenced by getRandomFilenames().

◆ matrixMultiply2x2()

static RandomImageGenerator::matrixMultiply2x2 (   $matrix,
  $x,
  $y 
)
staticprivate

Given a matrix and a pair of images, return new position.

Parameters
array$matrix2x2 rotation matrix
int$xx-coordinate number
int$yy-coordinate number
Returns
array Transformed with properties x, y

Definition at line 355 of file RandomImageGenerator.php.

References array().

Referenced by rotateImageSpec().

◆ rotateImageSpec()

static RandomImageGenerator::rotateImageSpec ( $spec,
  $matrix 
)
staticprivate

Given an image specification, produce rotated version This is used when simulating a rotated image capture with Exif orientation.

Parameters
$specObject returned by getImageSpec
$matrix2x2 transformation matrix
Returns
array transformed Spec

Definition at line 316 of file RandomImageGenerator.php.

References array(), as, and matrixMultiply2x2().

Referenced by writeImageWithApi().

◆ shapePointsToString()

static RandomImageGenerator::shapePointsToString (   $shape)
static

Given array( array('x' => 10, 'y' => 20), array( 'x' => 30, y=> 5 ) ) returns "10,20 30,5" Useful for SVG and imagemagick command line arguments.

Parameters
array$shapeArray of arrays, each array containing x & y keys mapped to numeric values
Returns
string

Definition at line 214 of file RandomImageGenerator.php.

References $points, array(), and as.

Referenced by writeImageWithCommandLine().

◆ writeImages()

RandomImageGenerator::writeImages (   $number,
  $format = 'jpg',
  $dir = null 
)

Writes random images with random filenames to disk in the directory you specify, or current working directory.

Parameters
int$numbernumber of filenames to write
string$formatoptional, must be understood by ImageMagick, such as 'jpg' or 'gif'
string$dirdirectory, optional (will default to current working directory)
Returns
array filenames we just wrote

Definition at line 104 of file RandomImageGenerator.php.

References $dir, as, getImageSpec(), getImageWriteMethod(), and getRandomFilenames().

◆ writeImageWithApi()

RandomImageGenerator::writeImageWithApi (   $spec,
  $format,
  $filename 
)

Based on an image specification, write such an image to disk, using Imagick PHP extension.

Parameters
array$specspec describing background and circles to draw
string$formatfile format to write
string$filenamefilename to write to

Definition at line 261 of file RandomImageGenerator.php.

References $retval, as, global, rotateImageSpec(), wfEscapeShellArg(), and wfShellExec().

◆ writeImageWithCommandLine()

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

Parameters
array$specspec describing background and shapes to draw
string$formatfile format to write (unused by this method but kept so it has the same signature as writeImageWithApi)
string$filenamefilename to write to
Returns
bool

Definition at line 378 of file RandomImageGenerator.php.

References $args, $command, $retval, array(), as, global, shapePointsToString(), wfEscapeShellArg(), and wfShellExec().

◆ writeSvg()

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. :)

Parameters
array$specspec describing background and shapes to draw
string$formatfile format to write (which is obviously always svg here)
string$filenamefilename to write to
Exceptions
Exception

Definition at line 233 of file RandomImageGenerator.php.

References as.

Member Data Documentation

◆ $dictionaryFile

RandomImageGenerator::$dictionaryFile
private

Definition at line 29 of file RandomImageGenerator.php.

Referenced by __construct(), and getRandomLines().

◆ $maxHeight

RandomImageGenerator::$maxHeight = 800
private

Definition at line 33 of file RandomImageGenerator.php.

◆ $maxWidth

RandomImageGenerator::$maxWidth = 800
private

Definition at line 31 of file RandomImageGenerator.php.

◆ $minHeight

RandomImageGenerator::$minHeight = 400
private

Definition at line 32 of file RandomImageGenerator.php.

◆ $minWidth

RandomImageGenerator::$minWidth = 400
private

Definition at line 30 of file RandomImageGenerator.php.

◆ $orientations

RandomImageGenerator::$orientations
staticprivate
Initial value:
'0thRow' => 'top',
'0thCol' => 'left',
'exifCode' => 1,
'counterRotation' => array( array( 1, 0 ), array( 0, 1 ) )
),
'0thRow' => 'bottom',
'0thCol' => 'right',
'exifCode' => 3,
'counterRotation' => array( array( -1, 0 ), array( 0, -1 ) )
),
'0thRow' => 'right',
'0thCol' => 'top',
'exifCode' => 6,
'counterRotation' => array( array( 0, 1 ), array( 1, 0 ) )
),
'0thRow' => 'left',
'0thCol' => 'bottom',
'exifCode' => 8,
'counterRotation' => array( array( 0, -1 ), array( -1, 0 ) )
)
)

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 42 of file RandomImageGenerator.php.

◆ $shapesToDraw

RandomImageGenerator::$shapesToDraw = 5
private

Definition at line 34 of file RandomImageGenerator.php.

Referenced by getImageSpec().


The documentation for this class was generated from the following file:
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.