break; case IMAGETYPE_PNG: $result = imagepng($dst_img, $dst); break; } if (!$result) { $this->msg = "Failed to save the cropped image file"; } } else { $this->msg = "Failed to crop the image file"; } imagedestroy($src_img); imagedestroy($dst_img); } } public function getResult() { return !empty($this->data) ? $this->dst : $this->src; } public function getMsg() { return $this->msg; } public function getId() { return $this->id; } } $crop = new CropAvatar($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['avatar_file'], $id); $response = array('state' => 200, 'message' => $crop->getMsg(), 'result' => $crop->getResult(), 'id' => $crop->getId()); echo json_encode($response);