PHPRtfLite_Image::createFromFile PHP Méthode

createFromFile() public static méthode

creates rtf image from file
public static createFromFile ( PHPRtfLite $rtf, string $file, float $width = null, float $height = null ) : PHPRtfLite_Image
$rtf PHPRtfLite
$file string
$width float optional
$height float optional
Résultat PHPRtfLite_Image
    public static function createFromFile(PHPRtfLite $rtf, $file, $width = null, $height = null)
    {
        if (is_readable($file)) {
            $stream = fopen($file, 'rb');
            $pathInfo = pathinfo($file);
            $type = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : 'jpeg';
            $image = self::create($rtf, $stream, $type, $width, $height);
            if ($type != self::TYPE_WMF) {
                list($width, $height, $imageType) = getimagesize($file);
                $imageType = image_type_to_extension($imageType, false);
                $image->setImageWidth($width);
                $image->setImageHeight($height);
                if ($type != $imageType) {
                    $image->setImageType($imageType);
                }
            }
            return $image;
        }
        return self::createMissingImage($rtf, $width, $height);
    }

Usage Example

Exemple #1
0
 /**
  * adds image to element container.
  *
  * @param string                $fileName   name of image file.
  * @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 addImage($fileName, PHPRtfLite_ParFormat $parFormat = null, $width = null, $height = null)
 {
     $image = PHPRtfLite_Image::createFromFile($this->_rtf, $fileName, $width, $height);
     if ($parFormat) {
         $image->setParFormat($parFormat);
     }
     $this->_elements[] = $image;
     return $image;
 }
All Usage Examples Of PHPRtfLite_Image::createFromFile