public function crop($start_x, $start_y, $end_x, $end_y)
{
// this method might be also called internally
// in this case, there's a fifth argument that points to an already existing image identifier
$args = func_get_args();
// if fifth argument exists
if (isset($args[4]) && is_resource($args[4])) {
// that it is the image identifier that we'll be using further on
$this->source_identifier = $args[4];
// set this to true so that the script will continue to execute at the next IF
$result = true;
// if method is called as usually
// try to create an image resource from source path
} else {
$result = $this->_create_from_source();
}
// if image resource was successfully created
if ($result !== false) {
// prepare the target image
$target_identifier = $this->_prepare_image($end_x - $start_x, $end_y - $start_y, -1);
// crop the image
imagecopyresampled($target_identifier, $this->source_identifier, 0, 0, $start_x, $start_y, $end_x - $start_x, $end_y - $start_y, $end_x - $start_x, $end_y - $start_y);
// write image
return $this->_write_image($target_identifier);
}
// if script gets this far, return false
// note that we do not set the error level as it has been already set
// by the _create_from_source() method earlier
return false;
}