Browse Source

Allow getting image data

Nathaniel van Diepen 6 years ago
parent
commit
84f1780bbe
1 changed files with 8 additions and 5 deletions
  1. 8 5
      image.class.php

+ 8 - 5
image.class.php

@@ -52,17 +52,20 @@
 			imagedestroy($this->img);
 		}
 		public function jsonSerialize(){
-			ob_start();
-			$this();
-			$data = ob_get_contents();
-			ob_end_clean();
 			return array(
 				'width'=>$this->width,
 				'height'=>$this->height,
 				'type'=>$this->type,
-				'data'=>'data:image/'.$this->type.';base64,'.base64_encode($data)
+				'data'=>'data:image/'.$this->type.';base64,'.base64_encode($this->toData())
 			);
 		}
+		public function toData(){
+			ob_start();
+			$this();
+			$data = ob_get_contents();
+			ob_end_clean();
+			return $data;
+		}
 		public function __toString(){
 			return '[Image Object ('.$this->width.','.$this->height.')]';
 		}