DOCUMENTATION.

1.2

PHP Configuration

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);
?>

Options

Here are all of the options:

upload_dir

Upload directory path

  • Type: string
  • Default: server/files/

upload_url

Upload directory url

  • Type: string
  • Default: full url to server/files/

accept_file_types

Accepted file types.

  • Type: string
  • Default: png|jpg|jpeg|gif

mkdir_mode

Directory mode.

  • Type: integer
  • Default: 0777

max_file_size

File max size restriction in bytes (e.g. 5000000 = 5MB).

  • Type: integer
  • Default: null

min_file_size

File min size restriction in bytes (e.g. 1 = 1B).

  • Type: integer
  • Default: 1

max_width

Image max width restriction (e.g. 100 = 100 pixels).

  • Type: integer
  • Default: null

max_height

Image max height restriction (e.g. 100 = 100 pixels).

  • Type: integer
  • Default: null

min_width

Image min width restriction (e.g. 100 = 100 pixels).

  • Type: integer
  • Default: 1

min_height

Image min height restriction (e.g. 100 = 100 pixels).

  • Type: integer
  • Default: 1

versions

Image versions. Array with image versions to be created. Each element is another array which has can have other options.

  • Type: array
  • Default: 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
    ),
)

Callback Options

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

load

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');
},

delete

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;
},

upload_start

Called before the upload starts.

 /**
 *  @param  stdClass        $image
 *  @param  ImgPicker       $instance
 *  @return void
 */
'upload_start' => function($image, $instance) {
},

upload_complete

Called after upload.

 /**
 *  @param  stdClass        $image
 *  @param  ImgPicker       $instance
 *  @return void
 */
'upload_complete' => function($image, $instance) {
},

crop_start

Called before the crop starts.

 /**
 *  @param  stdClass        $image
 *  @param  ImgPicker       $instance
 *  @return void
 */
'crop_start' => function($image, $instance) {
},

crop_complete

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 string
  • type string
  • size integer (available only in upload_start)
  • path string
  • url string
  • width integer
  • height integer
  • versions array (available only in upload_complete and crop_complete)

You can access them like this: $image->name, $image->path.