Skip to content

Commit 5678368

Browse files
author
Mitch
committed
Rename get() to getImageAsString(), and change implementation to not use output buffering
1 parent cd130af commit 5678368

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/ImageResize.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,22 @@ public function save($filename, $image_type = null, $quality = null, $permission
229229
}
230230

231231
/**
232-
* Get image as string
232+
* Convert the image to string
233233
*
234234
* @param int $image_type
235235
* @param int $quality
236236
* @return string
237237
*/
238-
public function get($image_type = null, $quality = null){
239-
ob_start();
240-
$this->save(null, $image_type, $quality);
241-
return ob_get_clean();
238+
public function getImageAsString($image_type = null, $quality = null){
239+
$string_temp = tempnam('', '');
240+
241+
$this->save($string_temp, $image_type, $quality);
242+
243+
$string = file_get_contents($string_temp);
244+
245+
unlink($string_temp);
246+
247+
return $string;
242248
}
243249

244250
/**
@@ -247,7 +253,7 @@ public function get($image_type = null, $quality = null){
247253
* @return string
248254
*/
249255
public function __toString(){
250-
return $this->get();
256+
return $this->getImageAsString();
251257
}
252258

253259
/**

test/Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ public function testSaveChmod() {
216216
$this->assertEquals(600, substr(decoct(fileperms($filename)), 3));
217217
}
218218

219-
public function testGet(){
219+
public function testGetImageAsString(){
220220
$resize = ImageResize::createFromString(base64_decode($this->image_string));
221-
$image = $resize->get();
221+
$image = $resize->getImageAsString();
222222
$this->assertEquals(79, strlen($image));
223223
}
224224

0 commit comments

Comments
 (0)