<?php require_once dirname(__FILE__) . '/aws.phar'; use Aws\Lambda\LambdaClient; $_ENV['IMOS_LAMBDA_FUNCTION'] = $_ENV['IMOS_LAMBDA_FUNCTION'] ?: 'exec'; $client = LambdaClient::factory(array('profile' => 'default', 'region' => $_ENV['IMOS_LAMBDA_REGION'] ?: 'ap-northeast-1', 'version' => '2015-03-31')); function GetRequest($argv) { $request = []; if (isset($_ENV['IMOS_LAMBDA_BUCKET'])) { $request['bucket'] = $_ENV['IMOS_LAMBDA_BUCKET']; } if (isset($_ENV['IMOS_LAMBDA_INPUT'])) { $file = $_ENV['IMOS_LAMBDA_INPUT']; if (!is_readable($file)) { fwrite(STDERR, "Input is unreadable: {$file}\n"); return 1; } $request['input'] = file_get_contents($_ENV['IMOS_LAMBDA_INPUT']); } if (isset($_ENV['IMOS_LAMBDA_ARGUMENTS'])) { $request['arguments'] = $_ENV['IMOS_LAMBDA_ARGUMENTS']; } if (isset($_ENV['IMOS_LAMBDA_OBJECT'])) { $request['object'] = $_ENV['IMOS_LAMBDA_OBJECT']; } $arg0 = array_shift($argv); $command = implode(' ', $argv); if (trim($command) != '') { $request['command'] = $command; }
/** * Streams current image to browser. * * @since 3.5.0 * @access public * * @param string $mime_type * @return bool|WP_Error */ public function stream($mime_type = null) { $ext = $this->get_extension($mime_type); list($filename, $extension, $mime_type) = $this->get_output_format("stream.{$ext}", $mime_type); $args = $this->_get_lambda_args(['new_filename' => $filename, 'return' => 'stream']); $function = $this->_get_lambda_function(); $result = $this->_lambda_client->invoke(['FunctionName' => $function, 'Payload' => json_encode($args), 'InvocationType' => 'RequestResponse']); if ($result['StatusCode'] < 200 && $result['StatusCode'] >= 300) { return new WP_Error('image_stream_error', $result['FunctionError']); } $base64_data = $result['Payload']->getContents(); header("Content-Type: {$mime_type}"); print base64_decode($base64_data); return true; }