/** * update the uploaded image with an optimized kraked file * @param File $file * @param Array $tmpFile * @TODO need to remake cropped images */ public function onAfterLoad($file, $tmpFile) { $siteConfig = SiteConfig::current_site_config(); if (!$siteConfig->DisableKraken && $file->appCategory() === 'image') { $krakenService = new KrakenService(); $data = $krakenService->optimizeImage($file->getFullPath()); //check if optimization was success if ($data['success']) { //attempt to download the kraked file $krakedFile = $krakenService->getOptimizedImage($data['kraked_url']); //update the uploaded file file_put_contents($file->getFullPath(), $krakedFile); $file->Kraked = true; $file->write(); } } }
/** * Category name * * @return string */ public function appCategory() { if ($this->file) { return $this->file->appCategory(); } else { return File::get_app_category($this->getExtension()); } }
public function appCategory() { if ($this->file) { return $this->file->appCategory(); } else { // Hack to use the framework's built-in thumbnail support without creating a local file representation $tmpFile = new File(array('Name' => $this->Name, 'Filename' => $this->Name)); return $tmpFile->appCategory(); } }