13 use Magento\Framework\Api\Data\ImageContentInterfaceFactory;
26 private $imageContentFactory;
59 \
Magento\Framework\Api\Data\ImageContentInterfaceFactory $imageContentInterfaceFactory =
null 76 ->get(\
Magento\Framework\Api\Data\ImageContentInterfaceFactory::class);
96 return [
__(
'"%1" is not a valid file.',
$label)];
99 $allowImageTypes = [1 =>
'gif', 2 =>
'jpg', 3 =>
'png'];
101 if (!isset($allowImageTypes[$imageProp[2]])) {
102 return [
__(
'"%1" is not a valid image format.',
$label)];
107 if (
$extension != $allowImageTypes[$imageProp[2]]) {
108 $value[
'name'] = pathinfo(
$value[
'name'], PATHINFO_FILENAME) .
'.' . $allowImageTypes[$imageProp[2]];
111 $maxFileSize = ArrayObjectSearch::getArrayElementByName(
116 if ($maxFileSize !==
null) {
118 if ($maxFileSize < $size) {
123 $maxImageWidth = ArrayObjectSearch::getArrayElementByName(
127 if ($maxImageWidth !==
null) {
128 if ($maxImageWidth < $imageProp[0]) {
130 $errors[] =
__(
'"%1" width exceeds allowed value of %2 px.',
$label, $r);
134 $maxImageHeight = ArrayObjectSearch::getArrayElementByName(
138 if ($maxImageHeight !==
null) {
139 if ($maxImageHeight < $imageProp[1]) {
140 $r = $maxImageHeight;
141 $errors[] =
__(
'"%1" height exceeds allowed value of %2 px.',
$label, $r);
187 protected function processCustomerValue(array
$value)
192 $base64EncodedData = $this->
getFileProcessor()->getBase64EncodedData($temporaryFile);
195 $imageContentDataObject = $this->imageContentFactory->create()
197 ->setBase64EncodedData($base64EncodedData)
198 ->setType(
$value[
'type']);
203 return $imageContentDataObject;