When you create a new instance of ImgPicker
you can pass some options:
<?php
$options = array(
'upload_dir' => dirname(__FILE__) . '/../files/',
'max_file_size' => 3000000
)
new ImgPicker($options);
?>
Here are all of the options:
Upload directory path
server/files/
Upload directory url
server/files/
Accepted file types.
png|jpg|jpeg|gif
Directory mode.
0777
File max size restriction in bytes (e.g. 5000000 = 5MB).
null
File min size restriction in bytes (e.g. 1 = 1B).
1
Image max width restriction (e.g. 100 = 100 pixels).
null
Image max height restriction (e.g. 100 = 100 pixels).
null
Image min width restriction (e.g. 100 = 100 pixels).
1
Image min height restriction (e.g. 100 = 100 pixels).
1
Image versions. Array with image versions to be created. Each element is another array which has can have other options.
n/a
'versions' => array(
// This will create 2 image versions: the original one and a 200x200 one
'avatar' => array(
// Other upload directory path (Default: main upload_dir)
'upload_dir' => dirname(__FILE__) . '/../files/avatar/',
// Other upload directory url (Default: main upload_url)
'upload_url' => 'http://localhost/imgPicker/files/avatar/',
// Create square image (Default: false)
'crop' => true,
// Max width (Default: n/a)
'max_width' => 200,
// Max height (Default: n/a)
'max_height' => 200
),
)
If you want to have only one image create a version with an empty name:
'versions' => array(
// This will create only one image
'' => array(
// The same options as above can be used here
),
)
The callbacks are functions that will be called once an action is completed. In all of these callbacks you can retrive data sent from the Client Side using $_POST['data']
or $_GET['data']
for the load callback. To send data from the Client Side check out Options > data
Called when autoloading image.
/**
* @param ImgPicker $instance
* @return string|array
*/
'load' => function($instance) {
// You can make a query from your database and return the image:
// return '123.jpg'; | return array('1.jpg', '2.jpg');
},
Called when trying to delete image.
/**
* @param stdClass $filename
* @param ImgPicker $instance
* @return boolean
*/
'delete' => function($filename, $instance) {
// Wether to allow file deletion
return true;
},
Called before the upload starts.
/**
* @param stdClass $image
* @param ImgPicker $instance
* @return void
*/
'upload_start' => function($image, $instance) {
},
Called after upload.
/**
* @param stdClass $image
* @param ImgPicker $instance
* @return void
*/
'upload_complete' => function($image, $instance) {
},
Called before the crop starts.
/**
* @param stdClass $image
* @param ImgPicker $instance
* @return void
*/
'crop_start' => function($image, $instance) {
},
Called after cropping.
/**
* @param stdClass $image
* @param ImgPicker $instance
* @return void
*/
'crop_complete' => function($image, $instance) {
},
In all callbacks the $image
parameter is an stdClass object and has the following proprieties:
name
stringtype
stringsize
integer (available only in upload_start)path
stringurl
stringwidth
integerheight
integerversions
array (available only in upload_complete and crop_complete)You can access them like this: $image->name
, $image->path
.