Skip to content

Commit c00dd55

Browse files
ENGCOM-2955: [Forwardport] Making configurable settings for MAX_IMAGE_WIDTH and MAX_IMAGE_HEIGHT #17826
- Merge Pull Request #17826 from nmalevanec/magento2:2.3-develop-PR-port-15942 - Merged commits: 1. 88e26f2 2. 4410272
2 parents 0eb8677 + 4410272 commit c00dd55

File tree

9 files changed

+112
-8
lines changed

9 files changed

+112
-8
lines changed

app/code/Magento/Backend/Block/Media/Uploader.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Backend\Block\Media;
79

810
use Magento\Framework\App\ObjectManager;
911
use Magento\Framework\Serialize\Serializer\Json;
12+
use Magento\Framework\Image\Adapter\UploadConfigInterface;
1013

1114
/**
1215
* Adminhtml media library uploader
@@ -35,20 +38,29 @@ class Uploader extends \Magento\Backend\Block\Widget
3538
*/
3639
private $jsonEncoder;
3740

41+
/**
42+
* @var UploadConfigInterface
43+
*/
44+
private $imageConfig;
45+
3846
/**
3947
* @param \Magento\Backend\Block\Template\Context $context
4048
* @param \Magento\Framework\File\Size $fileSize
4149
* @param array $data
4250
* @param Json $jsonEncoder
51+
* @param UploadConfigInterface $imageConfig
4352
*/
4453
public function __construct(
4554
\Magento\Backend\Block\Template\Context $context,
4655
\Magento\Framework\File\Size $fileSize,
4756
array $data = [],
48-
Json $jsonEncoder = null
57+
Json $jsonEncoder = null,
58+
UploadConfigInterface $imageConfig = null
4959
) {
5060
$this->_fileSizeService = $fileSize;
5161
$this->jsonEncoder = $jsonEncoder ?: ObjectManager::getInstance()->get(Json::class);
62+
$this->imageConfig = $imageConfig ?: ObjectManager::getInstance()->get(UploadConfigInterface::class);
63+
5264
parent::__construct($context, $data);
5365
}
5466

@@ -90,6 +102,26 @@ public function getFileSizeService()
90102
return $this->_fileSizeService;
91103
}
92104

105+
/**
106+
* Get Image Upload Maximum Width Config.
107+
*
108+
* @return int
109+
*/
110+
public function getImageUploadMaxWidth()
111+
{
112+
return $this->imageConfig->getMaxWidth();
113+
}
114+
115+
/**
116+
* Get Image Upload Maximum Height Config.
117+
*
118+
* @return int
119+
*/
120+
public function getImageUploadMaxHeight()
121+
{
122+
return $this->imageConfig->getMaxHeight();
123+
}
124+
93125
/**
94126
* Prepares layout and set element renderer
95127
*

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@
336336
</depends>
337337
</field>
338338
</group>
339+
<group id="upload_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
340+
<label>Images Upload Configuration</label>
341+
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
342+
<label>Maximum Width</label>
343+
<validate>validate-greater-than-zero validate-number required-entry</validate>
344+
<comment>Maximum allowed width for uploaded image.</comment>
345+
</field>
346+
<field id="max_height" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
347+
<label>Maximum Height</label>
348+
<validate>validate-greater-than-zero validate-number required-entry</validate>
349+
<comment>Maximum allowed height for uploaded image.</comment>
350+
</field>
351+
</group>
339352
</section>
340353
<section id="admin" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
341354
<label>Admin</label>

app/code/Magento/Backend/etc/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<dashboard>
2929
<enable_charts>1</enable_charts>
3030
</dashboard>
31+
<upload_configuration>
32+
<max_width>1920</max_width>
33+
<max_height>1200</max_height>
34+
</upload_configuration>
3135
</system>
3236
<general>
3337
<validator_data>

app/code/Magento/Backend/view/adminhtml/templates/media/uploader.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
data-mage-init='{
1414
"Magento_Backend/js/media-uploader" : {
1515
"maxFileSize": <?= /* @escapeNotVerified */ $block->getFileSizeService()->getMaxFileSize() ?>,
16-
"maxWidth":<?= /* @escapeNotVerified */ \Magento\Framework\File\Uploader::MAX_IMAGE_WIDTH ?> ,
17-
"maxHeight": <?= /* @escapeNotVerified */ \Magento\Framework\File\Uploader::MAX_IMAGE_HEIGHT ?>
16+
"maxWidth":<?= /* @escapeNotVerified */ $block->getImageUploadMaxWidth() ?> ,
17+
"maxHeight": <?= /* @escapeNotVerified */ $block->getImageUploadMaxHeight() ?>
1818
}
1919
}'
2020
>

app/code/Magento/Cms/view/adminhtml/templates/browser/content/uploader.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ require([
147147
maxFileSize: <?= (int) $block->getFileSizeService()->getMaxFileSize() ?> * 10
148148
}, {
149149
action: 'resize',
150-
maxWidth: <?= (float) \Magento\Framework\File\Uploader::MAX_IMAGE_WIDTH ?> ,
151-
maxHeight: <?= (float) \Magento\Framework\File\Uploader::MAX_IMAGE_HEIGHT ?>
150+
maxWidth: <?= /* @escapeNotVerified */ $block->getImageUploadMaxWidth() ?> ,
151+
maxHeight: <?= /* @escapeNotVerified */ $block->getImageUploadMaxHeight() ?>
152152
}, {
153153
action: 'save'
154154
}]

app/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<preference for="Magento\Framework\View\Design\Theme\CustomizationInterface" type="Magento\Framework\View\Design\Theme\Customization" />
8888
<preference for="Magento\Framework\View\Asset\ConfigInterface" type="Magento\Framework\View\Asset\Config" />
8989
<preference for="Magento\Framework\Image\Adapter\ConfigInterface" type="Magento\Framework\Image\Adapter\Config" />
90+
<preference for="Magento\Framework\Image\Adapter\UploadConfigInterface" type="Magento\Framework\Image\Adapter\Config" />
9091
<preference for="Magento\Framework\View\Design\Theme\Image\PathInterface" type="Magento\Theme\Model\Theme\Image\Path" />
9192
<preference for="Magento\Framework\Session\Config\ConfigInterface" type="Magento\Framework\Session\Config" />
9293
<preference for="Magento\Framework\Session\SidResolverInterface" type="Magento\Framework\Session\SidResolver\Proxy" />

lib/internal/Magento/Framework/File/Uploader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,16 @@ class Uploader
136136
const TMP_NAME_EMPTY = 666;
137137

138138
/**
139-
* Max Image Width resolution in pixels. For image resizing on client side
139+
* Maximum Image Width resolution in pixels. For image resizing on client side
140+
* @deprecated
141+
* @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxWidth()
140142
*/
141143
const MAX_IMAGE_WIDTH = 1920;
142144

143145
/**
144-
* Max Image Height resolution in pixels. For image resizing on client side
146+
* Maximum Image Height resolution in pixels. For image resizing on client side
147+
* @deprecated
148+
* @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxHeight()
145149
*/
146150
const MAX_IMAGE_HEIGHT = 1200;
147151

lib/internal/Magento/Framework/Image/Adapter/Config.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Framework\Image\Adapter;
79

8-
class Config implements \Magento\Framework\Image\Adapter\ConfigInterface
10+
class Config implements ConfigInterface, UploadConfigInterface
911
{
1012
const XML_PATH_IMAGE_ADAPTER = 'dev/image/default_adapter';
1113

1214
const XML_PATH_IMAGE_ADAPTERS = 'dev/image/adapters';
1315

16+
const XML_PATH_MAX_WIDTH_IMAGE = 'system/upload_configuration/max_width';
17+
18+
const XML_PATH_MAX_HEIGHT_IMAGE = 'system/upload_configuration/max_height';
19+
1420
/**
1521
* @var \Magento\Framework\App\Config\ScopeConfigInterface
1622
*/
@@ -43,4 +49,24 @@ public function getAdapters()
4349
{
4450
return $this->config->getValue(self::XML_PATH_IMAGE_ADAPTERS);
4551
}
52+
53+
/**
54+
* Get Maximum Image Width resolution in pixels. For image resizing on client side.
55+
*
56+
* @return int
57+
*/
58+
public function getMaxWidth(): int
59+
{
60+
return (int)$this->config->getValue(self::XML_PATH_MAX_WIDTH_IMAGE);
61+
}
62+
63+
/**
64+
* Get Maximum Image Height resolution in pixels. For image resizing on client side.
65+
*
66+
* @return int
67+
*/
68+
public function getMaxHeight(): int
69+
{
70+
return (int)$this->config->getValue(self::XML_PATH_MAX_HEIGHT_IMAGE);
71+
}
4672
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Image\Adapter;
9+
10+
/**
11+
* Interface UploadConfigInterface
12+
*/
13+
interface UploadConfigInterface
14+
{
15+
/**
16+
* @return int
17+
*/
18+
public function getMaxWidth(): int;
19+
20+
/**
21+
* @return int
22+
*/
23+
public function getMaxHeight(): int;
24+
}

0 commit comments

Comments
 (0)