Skip to content

Commit 2bea160

Browse files
committed
Update getRawOutput
Now you can retrieve the output from the generated image directly into a variable.
1 parent a4e6bb2 commit 2bea160

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/PNGQuant.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ function removeMetadata(){
147147
return $this->setOption('--strip');
148148
}
149149

150+
/**
151+
* Run the built command
152+
*/
150153
function execute(){
151154
$consoleInstruction = $this->buildCommand();
152155
$output = null;
@@ -155,4 +158,28 @@ function execute(){
155158

156159
return $output;
157160
}
161+
162+
/**
163+
* Execute PNGQUANT with the providen commands and retrieve the generated image
164+
* directly into a variable
165+
*/
166+
// Create a temporal file in the system
167+
$fileName = uniqid().'.png';
168+
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
169+
170+
// Set the output path the tmp file
171+
$this->setOutputImage($temp_file);
172+
173+
$consoleInstruction = $this->buildCommand();
174+
175+
$output = null;
176+
177+
system($consoleInstruction, $output);
178+
179+
return array(
180+
'statusCode' => $output,
181+
'tempFile' => $temp_file,
182+
'imageData' => file_get_contents($temp_file)
183+
);
184+
}
158185
}

0 commit comments

Comments
 (0)