PhpOffice\PhpPresentation\Slide\Background\Image::setPath PHP Method

setPath() public method

Set Path
public setPath ( string $pValue = '', boolean $pVerifyFile = true ) : PhpOffice\PhpPresentation\Shape\Drawing
$pValue string File path
$pVerifyFile boolean Verify file
return 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

Example #1
0
 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