public function testGetImageType() { $imageFile = new Garp_Image_File(); foreach ($this->_bogusValidImageFilenames as $filename) { $imageType = $imageFile->getImageType($filename); $this->assertTrue($imageType === IMAGETYPE_GIF || $imageType === IMAGETYPE_JPEG || $imageType === IMAGETYPE_PNG); } }
/** * @param Boolean $returnNonImageExtensions Whether to return only non-image extensions, or all uploadable extensions. * @return Array List of uploadable extensions */ public function getAllowedExtensions() { $ini = $this->_getIni(); $extensions = explode(',', $ini->cdn->extensions); $imageFile = new Garp_Image_File($this->_uploadOrStatic); $imageExtensions = $imageFile->getAllowedExtensions(); $extensions = array_filter($extensions, function ($element) use($imageExtensions) { return !in_array($element, $imageExtensions); }); return $extensions; }
protected function _scaleAndStoreForTemplate($sourceData, $imageType, $id, $template, $overwrite) { $file = new Garp_Image_File(Garp_File::FILE_VARIANT_UPLOAD); $scaleParams = $this->getTemplateParameters($template); // clone this scaler, since scaling parameters are stored as class properties $clonedScaler = clone $this; $scaledImageDataArray = $clonedScaler->scale($sourceData, $scaleParams, $imageType); $scaledFilePath = $this->getScaledPath($id, $template); if ($overwrite || !$file->exists($scaledFilePath)) { $file->store($scaledFilePath, $scaledImageDataArray['resource'], true, false); } }
/** * /g/content/download-zipped/dinges.pdf,jadda.gif/myZipArchiveName * * @return Void */ public function downloadzippedAction() { $params = $this->getRequest()->getParams(); if (!array_key_exists('files', $params) || !array_key_exists('zipname', $params) || !$params['files'] || !$params['zipname']) { throw new Exception('Please provide a filename list, and a name for the archive.'); } $zip = new ZipArchive(); $tmpDir = sys_get_temp_dir(); $tmpDir .= $tmpDir[strlen($tmpDir) - 1] !== '/' ? '/' : ''; $zipPath = $tmpDir . $params['zipname'] . '.zip'; if ($zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) { throw new Exception("Cannot open <{$zipPath}>\n"); } // @todo: als cdn niet lokaal is, moet je waarschijnlijk met zip::addFromString werken. $filenames = explode(',', $params['files']); $image = new Garp_Image_File(Garp_File::FILE_VARIANT_UPLOAD); $document = new Garp_File(null, Garp_File::FILE_VARIANT_UPLOAD); $ini = Zend_Registry::get('config'); $cdnIsLocal = $ini->cdn->type === "local"; foreach ($filenames as $filename) { $allowedImageExtensions = $image->getAllowedExtensions(); $filenameParts = explode('.', $filename); $extension = $filenameParts[count($filenameParts) - 1]; $fileIsImage = in_array($extension, $allowedImageExtensions); $file = $fileIsImage ? $image : $document; $url = $file->getUrl($filename); if ($content = @file_get_contents($url)) { $zip->addFromString('/' . $params['zipname'] . '/' . $filename, $content); } else { throw new Exception("{$url} could not be opened for inclusion in the zip archive."); } } $zip->close(); $this->_downloadFile($zipPath); @unlink($zipPath); }
protected function _scaleDatabaseImage(Garp_Db_Table_Row $record, Garp_Image_File $file, Garp_Image_Scaler $scaler, $template, $overwrite) { $id = $record->id; $filename = $record->filename; if (!$file->exists($filename)) { Garp_Cli::errorOut('Warning: ' . $filename . ' is in the database, but not on disk!'); return; } if ($file->exists($scaler->getScaledPath($id, $template, true)) && !$overwrite) { Garp_Cli::lineOut($template . '/' . $id . ' already exists, skipping'); return; } try { $scaler->scaleAndStore($filename, $id, $template, $overwrite); Garp_Cli::lineOut('Scaled image #' . $id . ': ' . $filename); return true; } catch (Exception $e) { Garp_Cli::errorOut("Error scaling " . $filename . " (#" . $id . "): " . $e->getMessage()); } }