Skip to content

Making configurable settings for MAX_IMAGE_WIDTH and MAX_IMAGE_HEIGHT #15942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 16, 2018

Conversation

eduard13
Copy link
Contributor

@eduard13 eduard13 commented Jun 7, 2018

Description

It was added a new system fieldset, where the max-width and max-height can be set.
Stores / Configuration / Advanced / System / Images Configuration

So these 2 values are more flexible now for those which need to have bigger images in their shops.

Fixed Issues (if relevant)

  1. Wysiwyg > Image Uploader >Max width/height #13747: Wysiwyg > Image Uploader >Max width/height
  2. ...

Manual testing scenarios

  1. Get an image of 3000x700
    https://dummyimage.com/3000x700
  2. Open any wysiwyg editor
  3. Upload an image
  4. The uploaded image should have maximum configured size

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@rogyar
Copy link
Contributor

rogyar commented Jun 11, 2018

Hello @eduard13, thank you for your PR. Please, consider fixing the failed static tests

@eduard13
Copy link
Contributor Author

Hi @rogyar, the failed tests were fixed.
Thank you.

@magento-engcom-team
Copy link
Contributor

@eduard13 thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@rogyar
Copy link
Contributor

rogyar commented Jun 20, 2018

@eduard13 great job!
I've added some minor changes. Among them, I've reverted the max width from 3000 to the 1920 as we had previously to prevent unexpected issues on the live installations. So, if there's a necessity to increase the limits for uploading images, an admin has this possibility.

@orlangur orlangur self-assigned this Jun 20, 2018
/**
* @var \Magento\Framework\Image\Adapter\ConfigInterface
*/
protected $imageConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use private for new fields.

array $data = []
) {
$this->_fileSizeService = $fileSize;
$this->imageConfig = $imageConfig;
parent::__construct($context, $data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check https://devdocs.magento.com/guides/v2.0/contributor-guide/backward-compatible-development/#php on how to add new dependency properly, always try to make parent constructor called first.

*/
public function getImageConfigService()
{
return $this->imageConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such method must be eliminated as it violates Law of Demeter, inject needed classes into blocks directly and introduce methods like getImageMaxWidth.

<group id="media_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Images Upload</label>
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Max Width</label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max -> Maximum

<label>Images Upload</label>
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Max Width</label>
<validate>validate-zero-or-greater validate-digits</validate>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think zero should be allowed. Validate integer instead of digits.

<field id="max_height" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Max Height</label>
<validate>validate-zero-or-greater validate-digits</validate>
<comment>Max allowed height for uploaded image.</comment>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same three notes as for width should be applied here.

@@ -43,4 +47,24 @@ public function getAdapters()
{
return $this->config->getValue(self::XML_PATH_IMAGE_ADAPTERS);
}

/**
* Get Max Image Width resolution in pixels. For image resizing on client side
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max -> Maximum

}

/**
* Get Max Image Height resolution in pixels. For image resizing on client side
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max -> Maximum

/**
* Max Image Height resolution in pixels. For image resizing on client side
*/
const MAX_IMAGE_HEIGHT = 1200;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants cannot be removed, see http://devdocs.magento.com/guides/v2.0/contributor-guide/backward-compatible-development/. Just deprecate them adding @see section.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<system>
<media_configuration>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be uploader_configuration, isn't it?

Currently these changes look flawed from modularity perspective. Configuration added to MediaStorage module but no logic in it, some code added to framework. Please arrange your changes properly.

eduard13 and others added 2 commits July 25, 2018 22:06
# Conflicts:
#	lib/internal/Magento/Framework/File/Uploader.php
@rogyar
Copy link
Contributor

rogyar commented Aug 9, 2018

Please, resolve conflicts with the mainline branch

@eduard13
Copy link
Contributor Author

@rogyar the conflicts were fixed. Moreover, I've changed the construct dependency into an optional one. Thank you.

/**
* @return int
*/
public function getMaxWidth();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't add new methods to existing interfaces, it would be better to introduce a new interface and implement this methods in Magento/Framework/Image/Adapter/Config.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sidolov a new interface was added and implemented. Thank you.

Copy link
Contributor

@sidolov sidolov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thank you! Just a few minor changes are required

@@ -18,7 +18,7 @@ protected function setUp()
{
$this->configMock = $this->createPartialMock(
\Magento\Framework\Image\Adapter\ConfigInterface::class,
['getAdapterAlias', 'getAdapters']
['getAdapterAlias', 'getAdapters', 'getMaxWidth', 'getMaxHeight']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove redundant method mocks

* Max Image Height resolution in pixels. For image resizing on client side
* Maximum Image Height resolution in pixels. For image resizing on client side
* @deprecated
* @see ConfigInterface::getMaxHeight()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess UploadConfigInterface should be here instead of ConfigInterface

@magento-engcom-team
Copy link
Contributor

Hi @eduard13. Thank you for your contribution.
We will aim to release these changes as part of 2.2.7.
Please check the release notes for final confirmation.

Please, consider to port this solution to 2.3 release line.
You may use Porting tool to port commits automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants