Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 933e496

Browse files
author
eduard13
committed
Making configurable settings for MAX_IMAGE_WIDTH and MAX_IMAGE_HEIGHT
1 parent 9ba75c8 commit 933e496

File tree

10 files changed

+100
-16
lines changed

10 files changed

+100
-16
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,25 @@ class Uploader extends \Magento\Backend\Block\Widget
2727
*/
2828
protected $_fileSizeService;
2929

30+
/**
31+
* @var \Magento\Framework\Image\Config
32+
*/
33+
protected $imageConfig;
34+
3035
/**
3136
* @param \Magento\Backend\Block\Template\Context $context
3237
* @param \Magento\Framework\File\Size $fileSize
3338
* @param array $data
39+
* @param \Magento\Framework\Image\Adapter\Config $imageConfig
3440
*/
3541
public function __construct(
3642
\Magento\Backend\Block\Template\Context $context,
3743
\Magento\Framework\File\Size $fileSize,
44+
\Magento\Framework\Image\Adapter\Config $imageConfig,
3845
array $data = []
3946
) {
4047
$this->_fileSizeService = $fileSize;
48+
$this->imageConfig = $imageConfig;
4149
parent::__construct($context, $data);
4250
}
4351

@@ -79,6 +87,16 @@ public function getFileSizeService()
7987
return $this->_fileSizeService;
8088
}
8189

90+
/**
91+
* Get image config
92+
*
93+
* @return \Magento\Framework\Image\Adapter\Config
94+
*/
95+
public function getImageConfigService()
96+
{
97+
return $this->imageConfig;
98+
}
99+
82100
/**
83101
* Prepares layout and set element renderer
84102
*

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->getImageConfigService()->getMaxWidth() ?> ,
17+
"maxHeight": <?= /* @escapeNotVerified */ $block->getImageConfigService()->getMaxHeight() ?>
1818
}
1919
}'
2020
>

app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Content/Uploader.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class Uploader extends \Magento\Backend\Block\Media\Uploader
1818
*/
1919
protected $_imagesStorage;
2020

21+
/**
22+
* @var \Magento\Framework\Image\Adapter\Config
23+
*/
24+
protected $imageConfig;
25+
2126
/**
2227
* @param \Magento\Backend\Block\Template\Context $context
2328
* @param \Magento\Framework\File\Size $fileSize
@@ -28,10 +33,12 @@ public function __construct(
2833
\Magento\Backend\Block\Template\Context $context,
2934
\Magento\Framework\File\Size $fileSize,
3035
\Magento\Cms\Model\Wysiwyg\Images\Storage $imagesStorage,
36+
\Magento\Framework\Image\Adapter\Config $imageConfig,
3137
array $data = []
3238
) {
3339
$this->_imagesStorage = $imagesStorage;
34-
parent::__construct($context, $fileSize, $data);
40+
$this->imageConfig = $imageConfig;
41+
parent::__construct($context, $fileSize, $imageConfig, $data);
3542
}
3643

3744
/**

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
@@ -101,8 +101,8 @@ require([
101101
maxFileSize: <?= (int) $block->getFileSizeService()->getMaxFileSize() ?> * 10
102102
}, {
103103
action: 'resize',
104-
maxWidth: <?= (float) \Magento\Framework\File\Uploader::MAX_IMAGE_WIDTH ?> ,
105-
maxHeight: <?= (float) \Magento\Framework\File\Uploader::MAX_IMAGE_HEIGHT ?>
104+
maxWidth: <?= (float) $block->getImageConfigService()->getMaxWidth() ?> ,
105+
maxHeight: <?= (float) $block->getImageConfigService()->getMaxHeight() ?>
106106
}, {
107107
action: 'save'
108108
}]

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
<label>Environment Update Time</label>
3131
</field>
3232
</group>
33+
<group id="media_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
34+
<label>Images Configuration</label>
35+
<field id="max_width" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
36+
<label>Max width</label>
37+
<validate>validate-zero-or-greater validate-digits</validate>
38+
</field>
39+
<field id="max_height" translate="label" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
40+
<label>Max height</label>
41+
<validate>validate-zero-or-greater validate-digits</validate>
42+
</field>
43+
</group>
3344
</section>
3445
</system>
3546
</config>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
9+
<default>
10+
<system>
11+
<media_configuration>
12+
<max_width>3200</max_width>
13+
<max_height>1200</max_height>
14+
</media_configuration>
15+
</system>
16+
</default>
17+
</config>

app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Uploader.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class Uploader extends \Magento\Backend\Block\Media\Uploader
2626
*/
2727
protected $_storageHelper;
2828

29+
/**
30+
* @var \Magento\Framework\Image\Adapter\Config
31+
*/
32+
protected $imageConfig;
33+
2934
/**
3035
* @param \Magento\Backend\Block\Template\Context $context
3136
* @param \Magento\Framework\File\Size $fileSize
@@ -36,10 +41,12 @@ public function __construct(
3641
\Magento\Backend\Block\Template\Context $context,
3742
\Magento\Framework\File\Size $fileSize,
3843
\Magento\Theme\Helper\Storage $storageHelper,
44+
\Magento\Framework\Image\Adapter\Config $imageConfig,
3945
array $data = []
4046
) {
4147
$this->_storageHelper = $storageHelper;
42-
parent::__construct($context, $fileSize, $data);
48+
$this->imageConfig = $imageConfig;
49+
parent::__construct($context, $fileSize, $imageConfig, $data);
4350
}
4451

4552
/**

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,6 @@ class Uploader
132132
*/
133133
const TMP_NAME_EMPTY = 666;
134134

135-
/**
136-
* Max Image Width resolution in pixels. For image resizing on client side
137-
*/
138-
const MAX_IMAGE_WIDTH = 1920;
139-
140-
/**
141-
* Max Image Height resolution in pixels. For image resizing on client side
142-
*/
143-
const MAX_IMAGE_HEIGHT = 1200;
144-
145135
/**
146136
* Resulting of uploaded file
147137
*

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class Config implements \Magento\Framework\Image\Adapter\ConfigInterface
1111

1212
const XML_PATH_IMAGE_ADAPTERS = 'dev/image/adapters';
1313

14+
const XML_PATH_MAX_WIDTH_IMAGE = 'system/media_configuration/max_width';
15+
16+
const XML_PATH_MAX_HEIGHT_IMAGE = 'system/media_configuration/max_height';
17+
1418
/**
1519
* @var \Magento\Framework\App\Config\ScopeConfigInterface
1620
*/
@@ -43,4 +47,24 @@ public function getAdapters()
4347
{
4448
return $this->config->getValue(self::XML_PATH_IMAGE_ADAPTERS);
4549
}
50+
51+
/**
52+
* Get Max Image Width resolution in pixels. For image resizing on client side
53+
*
54+
* @return int
55+
*/
56+
public function getMaxWidth()
57+
{
58+
return $this->config->getValue(self::XML_PATH_MAX_WIDTH_IMAGE);
59+
}
60+
61+
/**
62+
* Get Max Image Height resolution in pixels. For image resizing on client side
63+
*
64+
* @return int
65+
*/
66+
public function getMaxHeight()
67+
{
68+
return $this->config->getValue(self::XML_PATH_MAX_HEIGHT_IMAGE);
69+
}
4670
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ public function getAdapterAlias();
2020
* @return array
2121
*/
2222
public function getAdapters();
23+
24+
/**
25+
* @return int
26+
*/
27+
public function getMaxWidth();
28+
29+
/**
30+
* @return int
31+
*/
32+
public function getMaxHeight();
2333
}

0 commit comments

Comments
 (0)