Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-eav
Model
Attribute
Data
Image.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Eav\Model\Attribute\Data
;
7
13
class
Image
extends
\Magento\Eav\Model\Attribute\Data\File
14
{
24
protected
function
_validateByRules
(
$value
)
25
{
26
$label
=
__
($this->
getAttribute
()->
getStoreLabel
());
27
$rules
= $this->
getAttribute
()->getValidateRules();
28
29
$imageProp = @
getimagesize
(
$value
[
'tmp_name'
]);
30
31
$allowImageTypes = [1 =>
'gif'
, 2 =>
'jpg'
, 3 =>
'png'
];
32
33
if
(!isset($allowImageTypes[$imageProp[2]])) {
34
return
[
__
(
'"%1" is not a valid image format'
,
$label
)];
35
}
36
37
// modify image name
38
$extension
= pathinfo(
$value
[
'name'
], PATHINFO_EXTENSION);
39
if
(
$extension
!= $allowImageTypes[$imageProp[2]]) {
40
$value
[
'name'
] = pathinfo(
$value
[
'name'
], PATHINFO_FILENAME) .
'.'
. $allowImageTypes[$imageProp[2]];
41
}
42
43
$errors
= [];
44
if
(!empty(
$rules
[
'max_file_size'
])) {
45
$size =
$value
[
'size'
];
46
if
(
$rules
[
'max_file_size'
] < $size) {
47
$errors
[] =
__
(
'"%1" exceeds the allowed file size.'
,
$label
);
48
}
49
}
50
51
if
(!empty(
$rules
[
'max_image_width'
])) {
52
if
(
$rules
[
'max_image_width'
] < $imageProp[0]) {
53
$r =
$rules
[
'max_image_width'
];
54
$errors
[] =
__
(
'"%1" width exceeds allowed value of %2 px.'
,
$label
, $r);
55
}
56
}
57
if
(!empty(
$rules
[
'max_image_heght'
])) {
58
if
(
$rules
[
'max_image_heght'
] < $imageProp[1]) {
59
$r =
$rules
[
'max_image_heght'
];
60
$errors
[] =
__
(
'"%1" height exceeds allowed value of %2 px.'
,
$label
, $r);
61
}
62
}
63
64
return
$errors
;
65
}
66
}
Magento\Eav\Model\Entity\Attribute\getStoreLabel
getStoreLabel($storeId=null)
Definition:
Attribute.php:449
Magento\Eav\Model\Attribute\Data\Image\_validateByRules
_validateByRules($value)
Definition:
Image.php:24
Magento\Framework\Image\Adapter\getimagesize
getimagesize($file)
Definition:
global_php_mock.php:33
$extension
$extension
Definition:
downloadable_product_with_files_and_sample_url.php:125
Magento\Eav\Model\Attribute\Data\Image
Definition:
Image.php:13
Magento\Eav\Model\Attribute\Data\AbstractData\getAttribute
getAttribute()
Definition:
AbstractData.php:123
__
__()
Definition:
__.php:13
Magento\Eav\Model\Attribute\Data
Definition:
AbstractData.php:7
$rules
$rules
Definition:
classmap_generator.php:59
$label
$label
Definition:
details.phtml:21
$value
$value
Definition:
gender.phtml:16
$errors
$errors
Definition:
overview.phtml:9