/
home
/
obinna
/
html
/
cravings
/
app
/
Jobs
/
Upload File
HOME
<?php namespace App\Jobs; use App\Http\Services\ImageManager; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\DB; use Tinify\ClientException; class ProcessImage implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $files; protected $credentials; /** * Create a new job instance. * @param array $files array of files to process with file objects and url as keys for each file * @return void */ public function __construct(array $files) { $this->files = $files; $this->credentials = array( "service" => "s3", "aws_access_key_id" => env('S3_KEY'), "aws_secret_access_key" => env('S3_SECRET'), "region" => env('S3_REGION') ); } /** * Execute the job. * * @return void */ public function handle(ImageManager $im) { // process uploaded image foreach ($this->files as $i => $file) { try { $im = new ImageManager(); $source = $im->fromFile($file['file']); $base_image = $file['url']; $path = env('S3_BUCKET') . $base_image; $this->credentials['path'] = $path; $resized = $source->resize(array( "method" => "cover", "width" => 600, "height" => 600 )); $resized->store($this->credentials); if (file_exists($file['file'])) { try { unlink($file['file']); } catch (\Exception $e) { } } } catch (\Exception $e) { // $notdone[] = intval($i); } } } }