return uploaded file when generating image

This commit is contained in:
Philipp Lang 2022-11-21 10:28:44 +01:00
parent e00bdc1277
commit 199be4dc4d
1 changed files with 7 additions and 2 deletions

View File

@ -3,11 +3,14 @@
namespace Zoomyboy\Gradient;
use GdImage;
use Illuminate\Http\UploadedFile;
class GradientImage
{
public function generate(int $image_width, int $image_height, string $from, string $to, Degree $degree, Prop $prop = Prop::LINEAR): void
public function generate(int $image_width, int $image_height, string $from, string $to, Degree $degree, Prop $prop = Prop::LINEAR): UploadedFile
{
$filename = (string) str("{$from}-{$to}.png")->replace('#', '');
$from = $this->toRgb($from);
$to = $this->toRgb($to);
@ -15,8 +18,10 @@ class GradientImage
$image = $this->makeGradient($image, $from, $to, $prop->calculatorCallback());
$image = imagerotate($image, 360 - $degree->value, 0);
imagepng($image, 'image.png');
imagepng($image, "/tmp/{$filename}");
imagedestroy($image);
return new UploadedFile("/tmp/{$filename}", $filename, 'image/png');
}
public function toRgb(string $hexColor): RgbColor