2019-08-13 01:56:46 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-08-13 01:56:46 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-08-13 01:56:46 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\Util;
|
|
|
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2019-10-05 05:55:25 +02:00
|
|
|
use Illuminate\Http\File;
|
2019-08-13 01:56:46 +02:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2019-10-05 05:55:25 +02:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2019-08-13 01:56:46 +02:00
|
|
|
|
|
|
|
class UploadAvatar implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $file;
|
|
|
|
|
|
|
|
protected $directory;
|
|
|
|
|
|
|
|
public function __construct($file, $directory)
|
|
|
|
{
|
|
|
|
$this->file = $file;
|
|
|
|
$this->directory = $directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle() : ?string
|
|
|
|
{
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
//make dir
|
2020-12-03 22:24:34 +01:00
|
|
|
// info("avatar dir creation => ". $this->directory);
|
2020-12-03 22:22:31 +01:00
|
|
|
|
2020-12-03 22:24:34 +01:00
|
|
|
// Storage::makeDirectory($this->directory, 0775);
|
2019-08-13 01:56:46 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$tmp_file = sha1(time()).'.png';
|
2019-10-05 05:55:25 +02:00
|
|
|
|
2020-10-28 00:22:24 +01:00
|
|
|
$im = imagecreatefromstring(file_get_contents($this->file));
|
|
|
|
imagealphablending($im, false);
|
|
|
|
imagesavealpha($im, true);
|
|
|
|
$file_png = imagepng($im, sys_get_temp_dir().'/'.$tmp_file);
|
2019-08-13 01:56:46 +02:00
|
|
|
|
2020-10-28 00:22:24 +01:00
|
|
|
$path = Storage::putFile($this->directory, new File(sys_get_temp_dir().'/'.$tmp_file));
|
2020-09-06 11:38:10 +02:00
|
|
|
|
|
|
|
info($path);
|
|
|
|
info($tmp_file);
|
2020-06-15 08:06:32 +02:00
|
|
|
|
2019-08-13 01:56:46 +02:00
|
|
|
$url = Storage::url($path);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
//return file path
|
|
|
|
if ($url) {
|
|
|
|
return $url;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2019-08-13 01:56:46 +02:00
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|