/** * Get format from the image stream in the string. * @param string * @return mixed detected image format */ public static function getFormatFromString($s) { $types = array('image/jpeg' => self::JPEG, 'image/gif' => self::GIF, 'image/png' => self::PNG); $type = Utils\MimeTypeDetector::fromString($s); return isset($types[$type]) ? $types[$type] : NULL; }
/** * @param $file * @param $content * @param $contentType * @param $disposition * @return array * @throws FileNotFoundException */ private function createAttachment($file, $content, $contentType, $disposition) { if ($content === NULL) { $content = @file_get_contents($file); if ($content === FALSE) { throw new FileNotFoundException("Unable to read file '{$file}'."); } } else { $content = (string) $content; } $attachment = array('type' => $contentType ? $contentType : MimeTypeDetector::fromString($content), 'name' => Strings::fixEncoding(basename($file)), 'content' => rtrim(chunk_split(base64_encode($content), self::LINE_LENGTH, self::EOL))); return $attachment; }
/** * The data: URI generator. * @param string * @param string * @return string */ public static function dataStream($data, $type = NULL) { if ($type === NULL) { $type = Nette\Utils\MimeTypeDetector::fromString($data); } return 'data:' . ($type ? "{$type};" : '') . 'base64,' . base64_encode($data); }
/** * Creates file MIME part. * @return MimePart */ private function createAttachment($file, $content, $contentType, $disposition) { $part = new MimePart(); if ($content === NULL) { $content = file_get_contents($file); if ($content === FALSE) { throw new Nette\FileNotFoundException("Unable to read file '{$file}'."); } } else { $content = (string) $content; } $part->setBody($content); $part->setContentType($contentType ? $contentType : Nette\Utils\MimeTypeDetector::fromString($content)); $part->setEncoding(preg_match('#(multipart|message)/#A', $contentType) ? self::ENCODING_8BIT : self::ENCODING_BASE64); $part->setHeader('Content-Disposition', $disposition . '; filename="' . Strings::fixEncoding(basename($file)) . '"'); return $part; }
str_replace($search,$replacement,$subject);}static function dataStream($data,$type=NULL){if($type===NULL){$type=Nette\Utils\MimeTypeDetector::fromString($data,NULL);}return'data:'.($type?"$type;":'').'base64,'.base64_encode($data);}static
UnknownImageFileException("Unknown image type or file '$file' not found.");}}static function getFormatFromString($s){$types=array('image/jpeg'=>self::JPEG,'image/gif'=>self::GIF,'image/png'=>self::PNG);$type=Utils\MimeTypeDetector::fromString($s);return isset($types[$type])?$types[$type]:NULL;}static
/** * Returns the MIME content type of file. * * @param string * * @return string */ public static function fromString($data) { return Nette\Utils\MimeTypeDetector::fromString($data); }
/** * @param string $content * @param string|NULL $contentType */ public function __construct($content, $contentType = NULL) { $this->content = $content; $this->contentType = $contentType ? $contentType : MimeTypeDetector::fromString($content); }