MediaWiki  REL1_19
RandomImageGenerator Class Reference

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

List of all members.

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).
 getImageWriteMethod ($format)
 Figure out how we write images.
 getRandomColor ()
 Generate a string of random colors for ImageMagick or SVG, like "rgb(12, 37, 98)".
 writeImages ($number, $format= 'jpg', $dir=null)
 Writes random images with random filenames to disk in the directory you specify, or current working directory.
 writeImageWithApi ($spec, $format, $filename)
 Based on an image specification, write such an image to disk, using Imagick PHP extension.
 writeImageWithCommandLine ($spec, $format, $filename)
 Based on an image specification, write such an image to disk, using the command line ImageMagick program ('convert').
 writeSvg ($spec, $format, $filename)
 Based on image specification, write a very simple SVG file to disk.

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.

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.
 getRandomLines ($number_desired)
 Return N random lines from a file.
 getRandomWordPairs ($number)
 Get an array of random pairs of random words, like array( array( 'foo', 'bar' ), array( 'quux', 'baz' ) );.

Static Private Member Functions

static matrixMultiply2x2 ($matrix, $x, $y)
 Given a matrix and a pair of images, return new position.
static rotateImageSpec (&$spec, $matrix)
 Given an image specification, produce rotated version This is used when simulating a rotated image capture with EXIF orientation.

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.

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

RandomImageGenerator::__construct ( options = array())

Definition at line 70 of file RandomImageGenerator.php.

References $dictionaryFile, and $options.


Member Function Documentation

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

References getRandomColor().

Referenced by writeImages().

Here is the call graph for this function:

Here is the caller graph for this function:

Figure out how we write images.

This is a factor of both format and the local system

Parameters:
$format(a typical extension like 'svg', 'jpg', etc.)

Definition at line 117 of file RandomImageGenerator.php.

References $wgExiv2Command, $wgImageMagickConvertCommand, and $wgUseImageMagick.

Referenced by writeImages().

Here is the caller graph for this function:

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

Returns:
{String}

Definition at line 392 of file RandomImageGenerator.php.

Referenced by getImageSpec().

Here is the caller graph for this function:

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:
$numberInteger: of filenames to generate
$extensionString: optional, defaults to 'jpg'
$dirString: optional, defaults to current working directory
Returns:
Array: of filenames

Definition at line 142 of file RandomImageGenerator.php.

References $dir, and getRandomWordPairs().

Referenced by writeImages().

Here is the call graph for this function:

Here is the caller graph for this function:

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:
$number_desiredInteger: number of lines desired
Returns:
Array: of exactly n elements, drawn randomly from lines the file

Definition at line 426 of file RandomImageGenerator.php.

References $lines.

Referenced by getRandomWordPairs().

Here is the caller graph for this function:

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

Parameters:
$numberInteger: number of pairs
Returns:
Array: of two-element arrays

Definition at line 406 of file RandomImageGenerator.php.

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

Referenced by getRandomFilenames().

Here is the call graph for this function:

Here is the caller graph for this function:

static RandomImageGenerator::matrixMultiply2x2 ( matrix,
x,
y 
) [static, private]

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

Parameters:
$matrix,:2x2 rotation matrix
$x,:x-coordinate number
$y,:y-coordinate number
Returns:
Array transformed with properties x, y

Definition at line 347 of file RandomImageGenerator.php.

Referenced by rotateImageSpec().

Here is the caller graph for this function:

static RandomImageGenerator::rotateImageSpec ( &$  spec,
matrix 
) [static, private]

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:
transformed Spec

Definition at line 309 of file RandomImageGenerator.php.

References matrixMultiply2x2().

Referenced by writeImageWithApi().

Here is the call graph for this function:

Here is the caller graph for this function:

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:
$shape,:Array of arrays, each array containing x & y keys mapped to numeric values
Returns:
string

Definition at line 212 of file RandomImageGenerator.php.

Referenced by writeImageWithCommandLine().

Here is the caller graph for this function:

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:
$numberInteger: number of filenames to write
$formatString: optional, must be understood by ImageMagick, such as 'jpg' or 'gif'
$dirString: directory, optional (will default to current working directory)
Returns:
Array: filenames we just wrote

Definition at line 103 of file RandomImageGenerator.php.

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

Here is the call graph for this function:

RandomImageGenerator::writeImageWithApi ( spec,
format,
filename 
)

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

Parameters:
$spec,:spec describing background and circles to draw
$format,:file format to write
$filename,:filename to write to

Definition at line 254 of file RandomImageGenerator.php.

References $wgExiv2Command, print, rotateImageSpec(), wfEscapeShellArg(), and wfShellExec().

Here is the call graph for this function:

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:
$spec,:spec describing background and shapes to draw
$format,:file format to write (unused by this method but kept so it has the same signature as writeImageWithApi)
$filename,:filename to write to

Definition at line 368 of file RandomImageGenerator.php.

References $command, $wgImageMagickConvertCommand, shapePointsToString(), wfEscapeShellArg(), and wfShellExec().

Here is the call graph for this function:

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:
$spec,:spec describing background and shapes to draw
$format,:file format to write (which is obviously always svg here)
$filename,:filename to write to

Definition at line 227 of file RandomImageGenerator.php.


Member Data Documentation

RandomImageGenerator::$dictionaryFile [private]

Definition at line 29 of file RandomImageGenerator.php.

Referenced by __construct().

RandomImageGenerator::$maxHeight = 800 [private]

Definition at line 33 of file RandomImageGenerator.php.

RandomImageGenerator::$maxWidth = 800 [private]

Definition at line 31 of file RandomImageGenerator.php.

RandomImageGenerator::$minHeight = 400 [private]

Definition at line 32 of file RandomImageGenerator.php.

RandomImageGenerator::$minWidth = 400 [private]

Definition at line 30 of file RandomImageGenerator.php.

RandomImageGenerator::$orientations [static, private]
Initial value:
 array(
                array(
                        '0thRow' => 'top',
                        '0thCol' => 'left',
                        'exifCode' => 1,
                        'counterRotation' => array( array( 1, 0 ), array( 0, 1 ) )
                ),
                array(
                        '0thRow' => 'bottom',
                        '0thCol' => 'right',
                        'exifCode' => 3,
                        'counterRotation' => array( array( -1, 0 ), array( 0, -1 ) )
                ),
                array(
                        '0thRow' => 'right',
                        '0thCol' => 'top',
                        'exifCode' => 6,
                        'counterRotation' => array( array( 0, 1 ), array( 1, 0 ) )
                ),
                array(
                        '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.

RandomImageGenerator::$shapesToDraw = 5 [private]

Definition at line 34 of file RandomImageGenerator.php.


The documentation for this class was generated from the following file: