/** * 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 = Tools::detectMimeTypeFromString($s); return isset($types[$type]) ? $types[$type] : NULL; }
/** * The data: URI generator. * @param string * @param string * @return string */ public static function dataStream($data, $type = NULL) { if ($type === NULL) { $type = Nette\Tools::detectMimeTypeFromString($data, NULL); } return 'data:' . ($type ? "$type;" : '') . 'base64,' . base64_encode($data); }
/** * Creates file MIME part. * @return MailMimePart */ private function createAttachment($file, $content, $contentType, $disposition) { $part = new MailMimePart; if ($content === NULL) { $content = file_get_contents($file); if ($content === FALSE) { throw new \FileNotFoundException("Unable to read file '$file'."); } } else { $content = (string) $content; } $part->setBody($content); $part->setContentType($contentType ? $contentType : Nette\Tools::detectMimeTypeFromString($content)); $part->setEncoding(preg_match('#(multipart|message)/#A', $contentType) ? self::ENCODING_8BIT : self::ENCODING_BASE64); $part->setHeader('Content-Disposition', $disposition . '; filename="' . String::fixEncoding(basename($file)) . '"'); return $part; }