1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Jobs/Util/UploadAvatar.php

60 lines
1.4 KiB
PHP
Raw Normal View History

2019-08-13 01:56:46 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-08-13 01:56:46 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2019-08-13 01:56:46 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-08-13 01:56:46 +02:00
*/
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
{
2024-01-14 05:05:00 +01:00
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
2019-08-13 01:56:46 +02:00
protected $file;
protected $directory;
public function __construct($file, $directory)
{
$this->file = $file;
$this->directory = $directory;
}
2024-01-14 05:05:00 +01:00
public function handle(): ?string
2019-08-13 01:56:46 +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));
2019-08-13 01:56:46 +02:00
$url = Storage::url($path);
//return file path
if ($url) {
return $url;
} else {
return null;
}
2019-08-13 01:56:46 +02:00
}
}