The first argument of the ImgSelect class is for options:
new ImgSelect(array(
'upload_dir' => 'files/',
'accept_file_types' => 'png|jpg|jpeg|gif',
// other options...
));
The upload directory relative to the server folder.
filesThe accepted file types.
png|jpg|jpeg|gifThe mkdir mode used when creating the upload directory.
0755The maximum file size in bytes.
nullThe minimum file size in bytes.
1The maximum image width.
nullThe maximum image height.
nullThe minimum image width:
1The minimum image height.
1If the image size < crop size then force the resize.
trueThe crop maximum width.
nullThe crop maximum height.
nullbefore_upload($image) - Called before uploading the file to the server.
The $image object has the following properties:
name - Image name (including the extension).type - Image extension.size - Image size in bytes.path - Image path. url - Image url.width - Image width.height - image height.In this callback you can rename the uploaded file:
new ImgSelect(array(
// options...
`before_upload` => function ($image) {
$image->name = 'custom_name.'.$image->type;
},
));
upload_complete ($image) - Called when the upload is completed.
The $image object has the same properties as above.
before_crop ($crop) - Called before cropping the image.
The $crop object has the following properties:
file_name - The image name to be cropped.file_type - The image type.src_path, dst_path, src_h, src_w, src_y, src_x, dst_w and dst_h are described in ImgSelect.php in the resizeImage method. In this callback you may set the crop destionaton path so the original file will be keept:
new ImgSelect(array(
// options...
before_crop => function ($crop, $instance) {
$crop->dst_path = $instance->getUploadPath('my_image.'.$crop->file_type);
}
));
crop_complete ($image) - Called when the crop is completed.
The $image object has the same properties as above.
In this callback you may save the image into database using $image->name to get the image name.