function convert($Media, $mimeType) { if (Media::name(null, $mimeType) === 'Image') { $randomFrame = rand(1, $Media->objects['ffmpeg_movie']->getFrameCount() - 1); $resource = $Media->objects['ffmpeg_movie']->getFrame($randomFrame)->toGDImage(); if (!is_resource($resource)) { return false; } $Image = Media::factory(array('gd' => $resource), 'image/gd'); return $Image->convert($mimeType); } return false; }
function convert($Media, $mimeType) { if (!isset($this->_formatMap[$mimeType])) { return false; } try { $Media->objects['Imagick']->setFormat($this->_formatMap[$mimeType]); } catch (Exception $E) { return false; } if ($Media->name !== Media::name(null, $mimeType)) { // document -> image return Media::factory($Media->objects['Imagick']->clone(), $mimeType); } else { $Media->mimeType = $mimeType; } return true; }
function convert($Media, $mimeType) { if (Media::name(null, $mimeType) === 'Image') { $coverArt = $this->__coverArt($Media); if (!$coverArt) { return false; } $resource = @imagecreatefromstring($coverArt); if (!is_resource($resource)) { return false; } $Image = Media::factory(array('gd' => $resource), 'image/gd'); return $Image->convert($mimeType); } return false; }
/** * Factory method * * Takes a file and determines type of media to use for it * Falls back to generic media * * @param mixed $file See description of the constructor * @param string $mimeType Sets the mimeType of the new media * @return object */ static function &factory($file, $mimeType = null) { if ($mimeType === null) { $mimeType = MimeType::guessType($file, array('experimental' => false)); } $name = Media::name(null, $mimeType); $class = $name . 'Media'; if (!class_exists($class)) { App::import('Vendor', 'Media.' . $class, array('file' => 'media' . DS . strtolower($name) . '.php')); } $Object = new $class($file, $mimeType); return $Object; }
/** * Factory method * * Takes a file and determines type of media to use for it * Falls back to generic media * * @param mixed $file See description of the constructor * @param string $mimeType Sets the mimeType of the new media * @return object */ static function &factory($file, $mimeType = null) { if ($mimeType === null) { $mimeType = MimeType::guessType($file, array('experimental' => false)); } $name = Media::name(null, $mimeType); $class = $name . 'Media'; if (!class_exists($class)) { App::uses($class, 'Media.Libs/Media'); } $Object = new $class($file, $mimeType); return $Object; }
/** * Parses instruction sets and invokes `Media::make()` for a file * * @param Model $Model * @param string $file Path to a file relative to `baseDirectory` or an absolute path to a file * @param boolean Whether to overwrite existing versions with the same name or not * @return boolean */ function make(&$Model, $file, $overwrite = false) { extract($this->settings[$Model->alias]); list($file, $relativeFile) = $this->_file($Model, $file); $relativeDirectory = DS . rtrim(dirname($relativeFile), '.'); $name = Media::name($file); $filter = Configure::read('Media.filter.' . strtolower($name)); $hasCallback = method_exists($Model, 'beforeMake'); foreach ($filter as $version => $instructions) { $directory = Folder::slashTerm($filterDirectory . $version . $relativeDirectory); $Folder = new Folder($directory, $createDirectory); if (!$Folder->pwd()) { $message = "GeneratorBehavior::make - Directory `{$directory}` "; $message .= "could not be created or is not writable. "; $message .= "Please check the permissions."; trigger_error($message, E_USER_WARNING); continue; } if ($hasCallback) { $process = compact('overwrite', 'directory', 'name', 'version', 'instructions'); if ($Model->beforeMake($file, $process)) { continue; } } if (!($Media = Media::make($file, $instructions))) { $message = "GeneratorBehavior::make - Failed to make version `{$version}` "; $message .= "of file `{$file}`. "; trigger_error($message, E_USER_WARNING); continue; } $Media->store($directory . basename($file), $overwrite); } return true; }
/** * "makes" a file * * @param string $file Absolute path to a file * @access protected * @return boolean */ function _make($file) { $File = new File($file); $name = Media::name($file); $subdir = array_pop(explode(DS, dirname($this->source))); if ($name === 'Icon' || strpos($file, 'ico' . DS) !== false) { $message = "MakeTask::_make - "; $message .= "All functionality related to assets has been deprecated."; trigger_error($message, E_USER_NOTICE); return true; } if ($this->version) { $configString = 'Media.filter.' . strtolower($name) . '.' . $this->version; $filter = array(Configure::read($configString)); } else { $configString = 'Media.filter.' . strtolower($name); $filter = Configure::read($configString); } foreach ($filter as $version => $instructions) { $directory = Folder::slashTerm(rtrim($this->destination . $version . DS . $subdir, '.')); $Folder = new Folder($directory, $this->_createDirectories); if (!$Folder->pwd()) { $this->err($directory . ' could not be created or is not writable.'); $this->err('Please check your permissions.'); return false; } $Media = Media::make($File->pwd(), $instructions); if (!$Media) { $this->err('Failed to make version ' . $version . ' of media.'); return false; } $Media->store($Folder->pwd() . $File->name, $this->overwrite); } return true; }