/** * @brief Loads an image from a local file. * @param $imageref The path to a local file. * @returns An image resource or false on error */ public function loadFromFile($imagepath=false) { if(!is_file($imagepath) || !file_exists($imagepath) || !is_readable($imagepath)) { // Debug output disabled because this method is tried before loadFromBase64? OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.$imagepath, OC_Log::DEBUG); return false; } $itype = exif_imagetype($imagepath); switch($itype) { case IMAGETYPE_GIF: if (imagetypes() & IMG_GIF) { $this->resource = imagecreatefromgif($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, GIF images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_JPEG: if (imagetypes() & IMG_JPG) { $this->resource = imagecreatefromjpeg($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, JPG images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_PNG: if (imagetypes() & IMG_PNG) { $this->resource = imagecreatefrompng($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, PNG images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_XBM: if (imagetypes() & IMG_XPM) { $this->resource = imagecreatefromxbm($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, XBM/XPM images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_WBMP: if (imagetypes() & IMG_WBMP) { $this->resource = imagecreatefromwbmp($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, WBMP images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_BMP: $this->resource = $this->imagecreatefrombmp($imagepath); break; /* case IMAGETYPE_TIFF_II: // (intel byte order) break; case IMAGETYPE_TIFF_MM: // (motorola byte order) break; case IMAGETYPE_JPC: break; case IMAGETYPE_JP2: break; case IMAGETYPE_JPX: break; case IMAGETYPE_JB2: break; case IMAGETYPE_SWC: break; case IMAGETYPE_IFF: break; case IMAGETYPE_ICO: break; case IMAGETYPE_SWF: break; case IMAGETYPE_PSD: break; */ default: // this is mostly file created from encrypted file $this->resource = imagecreatefromstring(\OC_Filesystem::file_get_contents(\OC_Filesystem::getLocalPath($imagepath))); $itype = IMAGETYPE_PNG; OC_Log::write('core', 'OC_Image->loadFromFile, Default', OC_Log::DEBUG); break; } if($this->valid()) { $this->imagetype = $itype; $this->filepath = $imagepath; } return $this->resource; }