PHPRtfLite_Image::createFromString PHP Method

createFromString() public static method

creates rtf image from string
public static createFromString ( PHPRtfLite $rtf, string $string, string $type, float $width = null, float $height = null ) : PHPRtfLite_Image
$rtf PHPRtfLite
$string string
$type string (represented by class constants)
$width float optional
$height float optional
return PHPRtfLite_Image
    public static function createFromString(PHPRtfLite $rtf, $string, $type, $width = null, $height = null)
    {
        $stream = fopen('data://text/plain;base64,' . base64_encode($string), 'rb');
        $image = self::create($rtf, $stream, $type, $width, $height);
        if ($type != self::TYPE_WMF) {
            $imageResource = imagecreatefromstring($string);
            $image->setImageWidth(imagesx($imageResource));
            $image->setImageHeight(imagesy($imageResource));
        }
        return $image;
    }

Usage Example

コード例 #1
0
ファイル: Base.php プロジェクト: kalinin-sanja/FamilyTree
 /**
  * adds image to element container.
  *
  * @param string                $string     name of image file.
  * @param string                $type       class constants of PHPRtfLite_Image: TYPE_JPEG, TYPE_PNG, TYPE_WMF
  * @param PHPRtfLite_ParFormat  $parFormat  paragraph format, ff null image will appear in the same paragraph.
  * @param float                 $width      if null image is displayed by it's height.
  * @param float                 $height     if null image is displayed by it's width.
  *   If boths parameters are null, image is displayed as it is.
  *
  * @return PHPRtfLite_Image
  */
 public function addImageFromString($string, $type, PHPRtfLite_ParFormat $parFormat = null, $width = null, $height = null)
 {
     $image = PHPRtfLite_Image::createFromString($this->_rtf, $string, $type, $width, $height);
     if ($parFormat) {
         $image->setParFormat($parFormat);
     }
     $this->_elements[] = $image;
     return $image;
 }