Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
 /**
  * Returns the MIME content type of file.
  *
  * @param  string
  *
  * @return string
  */
 public static function fromString($data)
 {
     return Nette\Utils\MimeTypeDetector::fromString($data);
 }
Ejemplo n.º 8
0
 /**
  * @param string $content
  * @param string|NULL $contentType
  */
 public function __construct($content, $contentType = NULL)
 {
     $this->content = $content;
     $this->contentType = $contentType ? $contentType : MimeTypeDetector::fromString($content);
 }