KenedoProperty Type Image
PHP class: KenedoPropertyImage
Recommended column type: VARCHAR(127)
Object var: As property name (and others, see below)
Adds an image upload field in the backend edit screen, optionally creates variations of the image in multiple dimensions, adds KenedoModel::getRecord() data object vars with complete URLs and filesystem paths.
Typical property settings array
$propDefs['product_image'] = array (
'name'=>'product_image',
'type'=>'image',
'label'=>KText::_('Product Image'),
'allowedExtensions'=>array('jpg','jpeg','gif','tif','bmp','png'),
'allowedMimeTypes'=>array('image/pjpeg','image/jpg','image/jpeg','image/gif','image/tif','image/bmp','image/png'),
'maxFileSizeKb'=>'1000',
'minimumDimensions'=>array('width'=>1000, 'height'=>1000),
'appendSerial'=>1,
'dirBase'=>KenedoPlatform::p()->getDirDataStore().'/public/custom_media/product_images',
'urlBase'=>KenedoPlatform::p()->getUrlDataStore().'/public/custom_media/product_images',
'options'=>'FILENAME_TO_RECORD_ID',
'mutations'=>array(
'thumbnail_1x' => array(
'mode' => 'contain',
'params' => array(
'width' => 120,
'height' => 40,
),
),
'thumbnail_2x' => array(
'mode' => 'contain',
'params' => array(
'width' => 240,
'height' => 80,
),
),
'thumbnail_3x' => array(
'mode' => 'contain',
'params' => array(
'width' => 360,
'height' => 120,
),
),
),
'positionForm'=>1000,
);
Â
Data object variables
Assuming that the property’s name is ‘image’, the property type will add 3 variables (see KenedoModel::getRecord).
href to to the image: $record->image_href
filesystem path to the image: $record->image_path
filename: $record->image
See Image Mutations later in the article. For each image mutation you configure, the system will add more variables to the data object.
Property settings
allowedExtensions
Required: yes
Valid values: array of strings
List of allowed file extensions (without dots) for the uploaded file.
allowedMimeTypes
Required: yes
Valid values: array of strings
List of allowed MIME types for the uploaded file.
maxFileSizeKb
Required: yes
Valid values: number
Maximum file size for the uploaded file.
minimumDimensions
Required: yes
Valid values: associative array of numbers
Makes the system check for a minimum width and height. Provide an array in this form: array('width'=>1000, ‘height’=>1000).
appendSerial
Required: yes
Valid values: boolean
The system will append a random number to the filename each time a new file gets uploaded. Purpose is browser cache invalidation.
dirBase
Required: yes
Valid values: string
Provides the full filesystem path to the directory where to store the images.
Recommended place to store images is the Store or Customer data directory. See details about user data in this article.
In short, use KenedoPlatform::p()->getDirDataStore()
.'/public/custom_media/[some_sub_dir].
urlBase
Required: yes
Valid values: string
Provides the fully qualified URL to the directory where to store the images.
Recommended place to store images is the Store or Customer data directory. See details about user data in this article.
In short, use KenedoPlatform::p()->getUrlDataStore()
.'/public/custom_media/[some_sub_dir].
options
Required: no
Valid values: string
Provide ‘FILENAME_TO_RECORD_ID’ so that the system makes the filename of the image to the ID of the record. Else the original filename will be used.
mutations
Required: false
Valid values: multidimensional array
With this you instruct the system to create variations of the image in different dimensions. Each mutation will add object variables to the data object.
Basic data structure:
$propDefs['product_image'] = array (
'name'=>'product_image',
'mutations'=>array(
'thumbnail_1x' => array(
'mode' => 'contain',
'params' => array(
'width' => 120,
'height' => 40,
),
),
)
thumbnail_1x is the name of the first mutation. Pick any name. The data object (see KenedoModel::getRecord) will have 3 variables:
href to to the image: $record->product_image_thumbnail_1x_href
filesystem path to the image: $record->product_image_thumbnail_1x_path
filename: $record->product_image_thumbnail_1x
Modes:
In the example you see ‘contain’ as mode. There are the following modes:
contain
Parameters are ‘width’ and ‘height’, you need to provide at least one of them. The system will create a smaller image from the original, making the image fit into the given width and/or height.
forceRatioAndContain
Parameters are ‘width’ and ‘height’, both are required. The system will resize the image to the given dimensions and crops the image if needed (crops from the center)
cover
Parameters are ‘width’ and ‘height’, both are required. The system will resize the image to cover the given width and height, leaving one dimension larger if needed.