PhpOffice\PhpPresentation\Slide\Background\Image::setPath PHP Méthode

setPath() public méthode

Set Path
public setPath ( string $pValue = '', boolean $pVerifyFile = true ) : PhpOffice\PhpPresentation\Shape\Drawing
$pValue string File path
$pVerifyFile boolean Verify file
Résultat PhpOffice\PhpPresentation\Shape\Drawing
    public function setPath($pValue = '', $pVerifyFile = true)
    {
        if ($pVerifyFile) {
            if (!file_exists($pValue)) {
                throw new \Exception("File {$pValue} not found!");
            }
            if ($this->width == 0 && $this->height == 0) {
                // Get width/height
                list($this->width, $this->height) = getimagesize($pValue);
            }
        }
        $this->path = $pValue;
        return $this;
    }

Usage Example

 public function testColor()
 {
     $object = new Image();
     $imagePath = PHPPRESENTATION_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'PhpPresentationLogo.png';
     $numSlide = rand(1, 100);
     $this->assertNull($object->getPath());
     $this->assertEmpty($object->getFilename());
     $this->assertEmpty($object->getExtension());
     $this->assertEquals('background_' . $numSlide . '.', $object->getIndexedFilename($numSlide));
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Image', $object->setPath($imagePath));
     $this->assertEquals($imagePath, $object->getPath());
     $this->assertEquals('PhpPresentationLogo.png', $object->getFilename());
     $this->assertEquals('png', $object->getExtension());
     $this->assertEquals('background_' . $numSlide . '.png', $object->getIndexedFilename($numSlide));
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Image', $object->setPath(null, false));
     $this->assertNull($object->getPath());
     $this->assertEmpty($object->getFilename());
     $this->assertEmpty($object->getExtension());
     $this->assertEquals('background_' . $numSlide . '.', $object->getIndexedFilename($numSlide));
 }
All Usage Examples Of PhpOffice\PhpPresentation\Slide\Background\Image::setPath