data = $data; } /** * @return \Intervention\Image\Image|string * @throws MalformedRequestException */ public function getData() { // intervention/image v2: old //return in_array($this->getExtension(), ['pdf', 'excel', 'text']) ? $this->data : (new imageManager())->make($this->data); // intervention/image v3: new return in_array($this->getExtension(), ['pdf', 'excel', 'text']) ? $this->data : (new ImageManager(new Driver()))->read($this->data); } /** * @return string */ public function getFileName(): string { return (string) Str::uuid(); } /** * @return string */ public function getMimeType(): string { return finfo_file(finfo_open(), $this->data, FILEINFO_MIME_TYPE); } /** * @return string * @throws MalformedRequestException */ public function getExtension(): string { if (array_key_exists($this->getMimeType(), FileType::EXTENSION)) { return FileType::EXTENSION[$this->getMimeType()]; } throw new MalformedRequestException('Failed to save file due to Unknown file extension'); } /** * @return string * @throws MalformedRequestException */ public function getDecodedData(): string { // intervention/image v3: Use encode()->toDataUri() instead of encode('data-url')->encoded return in_array($this->getExtension(), ['pdf', 'excel', 'text']) ? base64_decode((explode('base64,', $this->getData()))[1]) : $this->getData()->encode()->toDataUri(); } /** * @param string $data */ public function setData(string $data): void { $this->data = $data; } }