/** * @param $file * @param null $path * @param null $resolution * @param null $name * @param int $max * @throws Exception */ public function imageUpload($file, $path = NULL, $resolution = NULL, $name = NULL, $max = 1024) { $this->file = $file; $this->file_size = $this->file['size']; $this->file_name = is_null($name) ? $this->file['tmp_name'] : htmlspecialchars($name); $mime2ext = array('image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/png' => 'png'); if ($this->file_size / 1024 <= $max) { $this->path_to_upload = $this->getSavePath($path); $image_info = getimagesize($this->file['tmp_name']); if ($image_info) { $image_xy = $resolution == NULL ? $image_info[0] . 'x' . $image_info[1] : $this->getImageResolution($resolution); $this->file_extension = $mime2ext[$image_info['mime']]; $this->file_name = $this->generateName($name); $static_image = 'system/images/static_image'; $static_image .= md5(microtime(true) * 1000); $static_image .= '.'; $static_image .= $this->file_extension; $tmp_file = file_get_contents($this->file['tmp_name']); file_put_contents($static_image, $tmp_file); $gd = new GDBasic(); ob_start(); $binery_data = $gd->resizeImage($static_image, $image_xy, false); $buffer = ob_get_clean(); $this->save($buffer); unlink($static_image); } else { throw new Exception('The system is failed to recognize the file as Image File'); } } else { throw new Exception('Max file size exceeded the limit. -'); } }
function __construct() { $this->resizeRatio = false; self::$open_error = "The given resource is NOT valid associative image format!"; }