public function __construct($file, $typeMime = null) { if (intval(ini_get('memory_limit')) < 32) { ini_set('memory_limit', '32M'); } if (!is_file($file)) { throw new Exception('fichier inexistant'); } if (!$typeMime) { $file_info = new Info($file); $this->type = $file_info->mime(); } else { $this->type = $typeMime; } $this->srcFile = $file; $this->type = $typeMime; switch ($this->type) { case "image/pjpeg": case "image/jpeg": case "image/jpg": $this->functionCreate = 'ImageCreateFromJpeg'; $this->functionSave = 'ImageJpeg'; break; case 'image/png': case "image/x-png": $this->functionCreate = 'ImageCreateFromPng'; $this->functionSave = 'ImagePNG'; break; case 'image/gif': $this->functionCreate = 'ImageCreateFromGif'; $this->functionSave = 'ImageGif'; break; default: throw new Exception('type de fichier non supporté'); } $my = $this->functionCreate; if (!($this->resTmp = $my($this->srcFile))) { throw new Exception(__METHOD__ . ' oops '); } $this->getSize(); imagesavealpha($this->resTmp, true); }
public function getTypeMime() { if (!$this->typeMime) { $t = new Info($this->file); $this->typeMime = $t->mime(); } return $this->typeMime; }