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.
files
The accepted file types.
png|jpg|jpeg|gif
The mkdir mode used when creating the upload directory.
0755
The maximum file size in bytes.
null
The minimum file size in bytes.
1
The maximum image width.
null
The maximum image height.
null
The minimum image width:
1
The minimum image height.
1
If the image size < crop size then force the resize.
true
The crop maximum width.
null
The crop maximum height.
null
before_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.