97614c2e357d2b0cff6c4a5bcb02497acead2b5d
[yaffs-website] / web / modules / contrib / imagemagick / src / ImagemagickFormatMapperInterface.php
1 <?php
2
3 namespace Drupal\imagemagick;
4
5 /**
6  * Provides an interface for ImageMagick format mappers.
7  */
8 interface ImagemagickFormatMapperInterface {
9
10   /**
11    * Validates the format map.
12    *
13    * The map is an associative array with ImageMagick image formats (e.g.
14    * JPEG, GIF87, etc.) as keys and an associative array of format variables
15    * as value. Each array element is structured like the following:
16    * @code
17    *   'TIFF' => [
18    *     'mime_type' => 'image/tiff',
19    *     'enabled' => true,
20    *     'weight' => 10,
21    *     'exclude_extensions' => 'tif, tifx',
22    *   ],
23    * @endcode
24    *
25    * The format variables are as follows:
26    * - 'mime_type': the MIME type of the image format. This is used to resolve
27    *    the supported file extensions, e.g. ImageMagick 'JPEG' format is mapped
28    *    to MIME type 'image/jpeg' which in turn will be mapped to 'jpeg jpg
29    *    jpe' image file extensions.
30    * - 'enabled': (optional) defines if the fomat needs to be enabled within
31    *   the toolkit. Defaults to TRUE.
32    * - 'weight': (optional) is used in cases where an image file extension is
33    *   mapped to more than one ImageMagick format. It is needed in file format
34    *   conversions, e.g. convert from 'png' to 'gif': shall 'GIF' or 'GIF87'
35    *   internal Imagemagick format be used? The format will lower weight will
36    *   be used. Defaults to 0.
37    * - 'exclude_extensions': (optional) is used to limit the file extensions
38    *   to be supported by the toolkit, if the mapping MIME type <-> file
39    *   extension returns more extensions than needed, and we do not want to
40    *   alter the MIME type mapping.
41    *
42    * @param array[] $map
43    *   An associative array with formats as keys and an associative array
44    *   of format variables as value.
45    *
46    * @return array[][]
47    *   An array of arrays of error strings.
48    */
49   public function validateMap(array $map);
50
51   /**
52    * Gets the list of currently enabled image formats.
53    *
54    * @return array
55    *   A simple array of image formats.
56    */
57   public function getEnabledFormats();
58
59   /**
60    * Gets the list of currently enabled image file extensions.
61    *
62    * @return array
63    *   A simple array of image file extensions.
64    */
65   public function getEnabledExtensions();
66
67   /**
68    * Checks if an image format is enabled in the toolkit.
69    *
70    * @param string $format
71    *   An image format in ImageMagick's internal representation (e.g. JPEG,
72    *   GIF87, etc.).
73    *
74    * @return bool
75    *   TRUE if the specified format is enabled within the toolkit, FALSE
76    *   otherwise.
77    */
78   public function isFormatEnabled($format);
79
80   /**
81    * Gets the MIME type of an image format.
82    *
83    * @param string $format
84    *   An image format in ImageMagick's internal representation (e.g. JPEG,
85    *   GIF87, etc.).
86    *
87    * @return string|null
88    *   The MIME type of the specified format if the format is enabled in the
89    *   toolkit, NULL otherwise.
90    */
91   public function getMimeTypeFromFormat($format);
92
93   /**
94    * Gets the image format, given the image file extension.
95    *
96    * @param string $extension
97    *   An image file extension (e.g. jpeg, jpg, png, etc.), without leading
98    *   dot.
99    *
100    * @return string|null
101    *   The ImageMagick internal format (e.g. JPEG, GIF87, etc.) of the
102    *   specified extension, if the format is enabled in the toolkit. NULL
103    *   otherwise.
104    */
105   public function getFormatFromExtension($extension);
106
107 }