GDToolkit
class GDToolkit extends ImageToolkitBase (View source)
Defines the GD2 toolkit for image manipulation within Drupal.
Traits
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Provides dependency injection friendly methods for serialization.
Provides a trait for the messenger service.
Constants
| DERIVATIVE_SEPARATOR |
A string which is used to separate base plugin IDs from the derivative ID. |
Properties
| protected string | $pluginId | The plugin_id. |
from PluginBase |
| protected array | $pluginDefinition | The plugin implementation definition. |
from PluginBase |
| protected array | $configuration | Configuration information passed into the plugin. |
from PluginBase |
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected array | $_serviceIds | An array of service IDs keyed by property name used for serialization. |
from DependencySerializationTrait |
| protected array | $_entityStorages | An array of entity type IDs keyed by the property name of their storages. |
from DependencySerializationTrait |
| protected MessengerInterface | $messenger | The messenger. |
from MessengerTrait |
| protected ConfigFactoryInterface | $configFactory | The config factory. |
from ImageToolkitBase |
| protected string | $source | Path of the image file. |
from ImageToolkitBase |
| protected ImageToolkitOperationManagerInterface | $operationManager | The image toolkit operation manager. |
from ImageToolkitBase |
| protected LoggerInterface | $logger | A logger instance. |
from ImageToolkitBase |
| protected resource|GdImage|null | $resource | A GD image resource. |
|
| protected int | $type | Image type represented by a PHP IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG). |
|
| protected array|null | $preLoadInfo | Image information from a file, available prior to loading the GD resource. |
|
| protected StreamWrapperManagerInterface | $streamWrapperManager | The StreamWrapper manager. |
|
| protected FileSystemInterface | $fileSystem | The file system. |
Methods
Constructs a GDToolkit object.
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Gets toolkit requirements in a format suitable for hook_requirements().
Gets a toolkit operation plugin instance.
Applies a toolkit operation to an image.
Destructs a GDToolkit object.
Creates an instance of the plugin.
Sets the GD image resource.
Retrieves the GD image resource.
Loads a GD resource from a file.
Checks if the image is valid.
Writes an image resource to a destination file.
Determines if a file contains a valid image.
Gets the color set for transparency in GIF images.
Returns the width of the image.
Returns the height of the image.
Gets the PHP type of the image.
Sets the PHP type of the image.
Returns the MIME type of the image file.
Verifies that the Image Toolkit is set up correctly.
Returns a list of image file extensions supported by the toolkit.
Returns the IMAGETYPE_xxx constant for the given extension.
Returns a list of image types supported by the toolkit.
Details
__construct(array $configuration, string $plugin_id, mixed $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager, FileSystemInterface $file_system)
Constructs a GDToolkit object.
string
getPluginId()
Gets the plugin_id of the plugin instance.
string
getBaseId()
Gets the base_plugin_id of the plugin instance.
string|null
getDerivativeId()
Gets the derivative_id of the plugin instance.
array
getPluginDefinition()
Gets the definition of the plugin implementation.
bool
isConfigurable()
Determines if the plugin is configurable.
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
setMessenger(MessengerInterface $messenger)
Sets the messenger.
MessengerInterface
messenger()
Gets the messenger.
validateConfigurationForm(array $form, FormStateInterface $form_state)
Form validation handler.
$this
setSource(string $source)
Sets the source path of the image file.
string
getSource()
Gets the source path of the image file.
array
getRequirements()
Gets toolkit requirements in a format suitable for hook_requirements().
protected ImageToolkitOperationInterface
getToolkitOperation(string $operation)
Gets a toolkit operation plugin instance.
bool
apply(string $operation, array $arguments = [])
Applies a toolkit operation to an image.
__destruct()
Destructs a GDToolkit object.
Frees memory associated with a GD image resource.
static ContainerFactoryPluginInterface
create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)
Creates an instance of the plugin.
$this
setResource(resource|GdImage $resource)
Sets the GD image resource.
resource|GdImage|null
getResource()
Retrieves the GD image resource.
array
buildConfigurationForm(array $form, FormStateInterface $form_state)
Form constructor.
Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and
array_parents, see \Drupal\Core\Render\Element\FormElement.
submitConfigurationForm(array $form, FormStateInterface $form_state)
Form submission handler.
protected bool
load()
Loads a GD resource from a file.
bool
isValid()
Checks if the image is valid.
bool
save(string $destination)
Writes an image resource to a destination file.
bool
parseFile()
Determines if a file contains a valid image.
Drupal supports GIF, JPG and PNG file formats when used with the GD toolkit, and may support others, depending on which toolkits are installed.
string|null
getTransparentColor()
Gets the color set for transparency in GIF images.
int|null
getWidth()
Returns the width of the image.
int|null
getHeight()
Returns the height of the image.
int
getType()
Gets the PHP type of the image.
$this
setType(int $type)
Sets the PHP type of the image.
string
getMimeType()
Returns the MIME type of the image file.
static bool
isAvailable()
Verifies that the Image Toolkit is set up correctly.
static array
getSupportedExtensions()
Returns a list of image file extensions supported by the toolkit.
int
extensionToImageType(string $extension)
Returns the IMAGETYPE_xxx constant for the given extension.
This is the reverse of the image_type_to_extension() function.
static protected array
supportedTypes()
Returns a list of image types supported by the toolkit.