In answering this question, I assume that you have generated your configuration via UI, and then exported it, as Kevin mentioned in his comment. This is the best way to create the initial config for inclusion in your project.
Note that all examples are shown using procedural code for simplicity's sake; be sure to follow best practices and inject your services when building your project.
ImageStyle entity
Once that configuration file is installed, it becomes an ImageStyle configuration entity, and can be manipulated like any configuration entity.
// Get the storag ehandler for ImageStyle entities.
$image_style_storage = \Drupal::entityTypeManager()->getStorage("image_style");
// Get an instance of our ImageStyle entity.
$my_image_style = $image_style_storage->load("my_image_style");
The effects that are specified in the ImageStyle definition are plugins managed by the plugin.manager.image.effect
plugin manager service.
As luck would have it, the ImageStyle entity offers the addImageEffect()
public method, which accepts an array of effects info. This method actually takes care of generating and assigning the UUID, which is then returned to you.
public function addImageEffect(array $configuration) {
$configuration['uuid'] = $this->uuidGenerator()->generate();
$this->getEffects()->addInstanceId($configuration['uuid'], $configuration);
return $configuration['uuid'];
}
So, using your image.style.max_1300x1300
example, assigning the image effect would look like:
$effect_uuid = $my_image_style->addImageEffect([
'id' => 'image_scale',
'data' => [
'width' => '1300',
'height' => '1300',
'upscale' => FALSE,
],
'weight' => 1,
]);
You can find all of the image effects registered on your site by executing:
\Drupal::service('plugin.manager.image.effect')->getDefinitions();