I've been tasked with resizing and possibly rotating images stored in an S3 bucket based on a set of business rules.
The following function is able to retrieve and echo the object keys:
public function retrieveObjects($orderNumber)
{
try {
$objects = $this->s3Client->listObjects([
'Bucket' => 'designproofs',
'Prefix' => $this->path . $orderNumber . '/'
]);
if(is_array($objects['Contents'])) {
foreach ($objects['Contents'] as $object) {
$result = $this->s3Client->getObject([
'Bucket' => 'designproofs',
'Key' => $object['Key'],
]);
echo $object['Key'] . "<br>";
}
}
else{
echo $objects['Key'] . "<br>";
echo $result['Body'] . "<br>";
}
} catch (S3Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
}
The $result['Body']
appears to be the binary image data -though I am not entirely certain.
Can I store these images in a variable and manipulate them without the need to write the file to a physical medium (HDD etc.)?
* EDIT *
The images can be easily stored with the following:
$result = $this->s3Client->getObject([
'Bucket' => 'easyflow-designproofs',
'Key' => $object['Key'],
'SaveAs' => 'upload/temp_images/' . $fileName
]);