JBZoo\Image\Image::getBase64 PHP Method

getBase64() public method

Outputs image as data base64 to use as img src
public getBase64 ( null | string $format = 'gif', integer | null $quality = null, $addMime = true ) : string
$format null | string If omitted or null - format of original file will be used, may be gif|jpg|png
$quality integer | null Output image quality in percents 0-100
return string
    public function getBase64($format = 'gif', $quality = null, $addMime = true)
    {
        list($mimeType, $binaryData) = $this->_renderBinary($format, $quality);
        $result = base64_encode($binaryData);
        if ($addMime) {
            $result = 'data:' . $mimeType . ';base64,' . $result;
        }
        return $result;
    }

Usage Example

Beispiel #1
0
 /**
  * @expectedException \JBZoo\Image\Exception
  */
 public function testToBase64Undefined()
 {
     $img = new Image();
     $img->getBase64();
 }