PhpOffice\PhpPresentation\Shape\Drawing\Gd::setImageResource PHP Method

setImageResource() public method

Set image resource
public setImageResource ( $value = null )
$value resource
    public function setImageResource($value = null)
    {
        $this->imageResource = $value;
        if (!is_null($this->imageResource)) {
            // Get width/height
            $this->width = imagesx($this->imageResource);
            $this->height = imagesy($this->imageResource);
        }
        return $this;
    }

Usage Example

 public function testMemoryDrawing()
 {
     $oPhpPresentation = new PhpPresentation();
     $oSlide = $oPhpPresentation->getActiveSlide();
     $oShape = new Drawing\Gd();
     $gdImage = @imagecreatetruecolor(140, 20);
     $textColor = imagecolorallocate($gdImage, 255, 255, 255);
     imagestring($gdImage, 1, 5, 5, 'Created with PhpPresentation', $textColor);
     $oShape->setImageResource($gdImage)->setRenderingFunction(Drawing\Gd::RENDERING_JPEG)->setMimeType(Drawing\Gd::MIMETYPE_DEFAULT);
     $oSlide->addShape($oShape);
     $pres = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation');
     $element = '/manifest:manifest/manifest:file-entry[5]';
     $this->assertTrue($pres->elementExists($element, 'META-INF/manifest.xml'));
     $this->assertEquals('Pictures/' . $oShape->getIndexedFilename(), $pres->getElementAttribute($element, 'manifest:full-path', 'META-INF/manifest.xml'));
 }
All Usage Examples Of PhpOffice\PhpPresentation\Shape\Drawing\Gd::setImageResource