Programmatically resize images uploaded When uploading images to D8 programmatically the setting for Maximum image resolution will be ignored and images will not be scaled down. Some of the images i have to upload are even larger then 10MB.

I am currently using this code.

$file_type = explode('.', $image)[1];
$data = file_get_contents($image);
$path = 'public://images/';

if (file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {

  $file = file_save_data($data, $path . md5($image) . '.' . $file_type, FILE_EXISTS_REPLACE);

  $node = Node::create(array(
    'type' =&gt; 'image',
    'title' =&gt; $image,
    'field_image' =&gt; array(
      'target_id' =&gt; $file-&gt;id(),
    ),
  ));
  $node-&gt;save();

}


I've tried to work with ImageStyle::load('max_2600x2600'), but that will only create a style in styles directory.

It would be possible to use a custom shell command but i would love to use the Drupal 8 way. How to make sure original images will get resized?
You can Use Image style before save the node.

$original_image = 'public://images/image.jpg';

// Load the image style configuration entity.
use Drupal\image\Entity\ImageStyle;
$style = ImageStyle::load('max_2600x2600');

$uri = $style-&gt;buildUri($original_image);
$url = $style-&gt;buildUrl($original_image);


Here some links may helps you

Drupal 8 - Create an Image and ImageStyle Programmatically

Drupal 8 images with image style

Flexible image style system