MediaWiki REL1_39
MediaWiki\ResourceLoader\Image Class Reference

Class encapsulating an image used in an ImageModule. More...

Public Member Functions

 __construct ( $name, $module, $descriptor, $basePath, array $variants, $defaultColor=null)
 
 getDataUri (Context $context, $variant, $format)
 Get the data: URI that will produce this image.
 
 getExtension ( $format='original')
 Get the extension of the image.
 
 getImageData (Context $context, $variant=false, $format=false)
 Get actual image data for this image.
 
 getMimeType ( $format='original')
 Get the MIME type of the image.
 
 getModule ()
 Get name of the module this image belongs to.
 
 getName ()
 Get name of this image.
 
 getPath (Context $context)
 Get the path to image file for given context.
 
 getUrl (Context $context, $script, $variant, $format)
 Get the load.php URL that will produce this image.
 
 getVariants ()
 Get the list of variants this image can be converted to.
 
 sendResponseHeaders (Context $context)
 Send response headers (using the header() function) that are necessary to correctly serve the image data for this image, as returned by getImageData().
 

Protected Member Functions

 getLangFallbacks (string $lang)
 
 getLocalPath ( $path)
 
 massageSvgPathdata ( $svg)
 Massage the SVG image data for converters which don't understand some path data syntax.
 
 rasterize ( $svg)
 Convert passed image data, which is assumed to be SVG, to PNG.
 
 variantize (array $variantConf, Context $context)
 Convert this image, which is assumed to be SVG, to given variant.
 

Detailed Description

Class encapsulating an image used in an ImageModule.

Since
1.25

Definition at line 41 of file Image.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\ResourceLoader\Image::__construct ( $name,
$module,
$descriptor,
$basePath,
array $variants,
$defaultColor = null )
Parameters
string$nameSelf-name of the image as known to ImageModule.
string$moduleSelf-name of the module containing this image. Used to find the image in the registry e.g. through a load.php url.
string | array$descriptorPath to image file, or array structure containing paths
string$basePathDirectory to which paths in descriptor refer
array$variants
string | null$defaultColorof the base variant

Definition at line 77 of file Image.php.

References $ext, $path, and MediaWiki\ResourceLoader\Image\getLocalPath().

Member Function Documentation

◆ getDataUri()

MediaWiki\ResourceLoader\Image::getDataUri ( Context $context,
$variant,
$format )

Get the data: URI that will produce this image.

Parameters
Context$contextAny context
string | null$variantVariant to get the URI for
string$formatFormat to get the URI for, 'original' or 'rasterized'
Returns
string

Definition at line 268 of file Image.php.

References $type.

◆ getExtension()

MediaWiki\ResourceLoader\Image::getExtension ( $format = 'original')

Get the extension of the image.

Parameters
string | null$formatFormat to get the extension for, 'original' or 'rasterized'
Returns
string Extension without leading dot, e.g. 'png'

Definition at line 215 of file Image.php.

◆ getImageData()

MediaWiki\ResourceLoader\Image::getImageData ( Context $context,
$variant = false,
$format = false )

Get actual image data for this image.

This can be saved to a file or sent to the browser to produce the converted image.

Call getExtension() or getMimeType() with the same $format argument to learn what file type the returned data uses.

Parameters
Context$contextImage context, or any context if $variant and $format given.
string | null | false$variantVariant to get the data for. Optional; if given, overrides the data from $context.
string | false$formatFormat to get the data for, 'original' or 'rasterized'. Optional; if given, overrides the data from $context.
Returns
string|false Possibly binary image data, or false on failure

Definition at line 289 of file Image.php.

References $path, MediaWiki\ResourceLoader\Context\getFormat(), MediaWiki\ResourceLoader\Context\getResourceLoader(), and MediaWiki\ResourceLoader\Context\getVariant().

◆ getLangFallbacks()

MediaWiki\ResourceLoader\Image::getLangFallbacks ( string $lang)
protected
Access: internal
For unit testing override
Parameters
string$lang
Returns
string[]

Definition at line 159 of file Image.php.

◆ getLocalPath()

MediaWiki\ResourceLoader\Image::getLocalPath ( $path)
protected
Parameters
string | FilePath$path
Returns
string

Definition at line 201 of file Image.php.

References $path.

Referenced by MediaWiki\ResourceLoader\Image\__construct().

◆ getMimeType()

MediaWiki\ResourceLoader\Image::getMimeType ( $format = 'original')

Get the MIME type of the image.

Parameters
string | null$formatFormat to get the MIME type for, 'original' or 'rasterized'
Returns
string

Definition at line 228 of file Image.php.

References $ext.

◆ getModule()

MediaWiki\ResourceLoader\Image::getModule ( )

Get name of the module this image belongs to.

Returns
string

Definition at line 141 of file Image.php.

◆ getName()

MediaWiki\ResourceLoader\Image::getName ( )

Get name of this image.

Returns
string

Definition at line 132 of file Image.php.

◆ getPath()

MediaWiki\ResourceLoader\Image::getPath ( Context $context)

Get the path to image file for given context.

Parameters
Context$contextAny context
Returns
string

Definition at line 171 of file Image.php.

References $lang, MediaWiki\ResourceLoader\Context\getDirection(), and MediaWiki\ResourceLoader\Context\getLanguage().

◆ getUrl()

MediaWiki\ResourceLoader\Image::getUrl ( Context $context,
$script,
$variant,
$format )

Get the load.php URL that will produce this image.

Parameters
Context$contextAny context
string$scriptURL to load.php
string | null$variantVariant to get the URL for
string$formatFormat to get the URL for, 'original' or 'rasterized'
Returns
string URL

Definition at line 242 of file Image.php.

References MediaWiki\ResourceLoader\Context\getLanguage(), MediaWiki\ResourceLoader\Context\getResourceLoader(), MediaWiki\ResourceLoader\Context\getSkin(), and wfAppendQuery().

◆ getVariants()

MediaWiki\ResourceLoader\Image::getVariants ( )

Get the list of variants this image can be converted to.

Returns
string[]

Definition at line 150 of file Image.php.

◆ massageSvgPathdata()

MediaWiki\ResourceLoader\Image::massageSvgPathdata ( $svg)
protected

Massage the SVG image data for converters which don't understand some path data syntax.

This is necessary for rsvg and ImageMagick when compiled with rsvg support. Upstream bug is https://bugzilla.gnome.org/show_bug.cgi?id=620923, fixed 2014-11-10, so this will be needed for a while. (T76852)

Parameters
string$svgSVG image data
Returns
string Massaged SVG image data

Definition at line 386 of file Image.php.

◆ rasterize()

MediaWiki\ResourceLoader\Image::rasterize ( $svg)
protected

Convert passed image data, which is assumed to be SVG, to PNG.

Parameters
string$svgSVG image data
Returns
string|bool PNG image data, or false on failure

Definition at line 407 of file Image.php.

References $command, $res, SvgHandler\rasterize(), and wfTempDir().

◆ sendResponseHeaders()

MediaWiki\ResourceLoader\Image::sendResponseHeaders ( Context $context)

Send response headers (using the header() function) that are necessary to correctly serve the image data for this image, as returned by getImageData().

Note that the headers are independent of the language or image variant.

Parameters
Context$contextImage context

Definition at line 334 of file Image.php.

◆ variantize()

MediaWiki\ResourceLoader\Image::variantize ( array $variantConf,
Context $context )
protected

Convert this image, which is assumed to be SVG, to given variant.

Parameters
array$variantConfArray with a 'color' key, its value will be used as fill color
Context$contextImage context
Returns
string New SVG file data

Definition at line 351 of file Image.php.


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