Hi Jacques1. Long time no see. Hope all is good.
Maybe no problems with the code. At my day job now and wrote it without trying it. I've never tried to do something like this, and didn't know I was close.
What am I trying to do? I wrote a little jQuery plugin which allows the user to select an image file on their local PC and then select the area of the image which they want, and the file and desired area coordinates are sent to the server. It also allows the user to delete the previously uploaded image and replace the target with a default image. The JavaScript is similar to:
$('.target').imageCropper('/path/to/server/script.php?task=doSomething');
To accompany the plugin, I also wrote a PHP class which has four public methods, and the method to execute is based on $_GET or $_POST['method_to_execute'].
init(). The configuration of the plugin is all defined serverside and the plugin gets the configuration settings from the server when it is initialed. upload(). Uploads the image and saves it in a temporary folder. update(). Crops and resizes the image and moves it to a permanent folder. delete(). Deletes the previously image which is stored in the permanent folder.
For the update() and delete() methods, I wish to allow some other custom functionality such as updating the database.
The PHP configuration would be something similar to the following:
public function doSomething()
{
$arr=array(
'path_to_save'=>'bla/bla/bla',
'ratio'=>2,
'default_image'=>'/bla/default.png',
'allowed_extentions'=>array('png','jpg'),
'other_stuff_to_override_default_settings'=>'bla',
'save'=> function($col1,$col2) {
// call back to save filename in database
$stmt=$this->pdo->prepare('UPDATE mytable SET col1=?, col2=? WHERE id=?');
$stmt->execute($col1,$col2,$this->id);
},
'delete'=>function() {
//As required
}
);
new imageCropper($arr); //Based on $_GET or $_POST['method_to_execute'], execute the appropriate method.
}
Make sense?