From 199be4dc4db73611e2b2b04c5fd4a7fb2ffae5ba Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Mon, 21 Nov 2022 10:28:44 +0100 Subject: [PATCH] return uploaded file when generating image --- src/GradientImage.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GradientImage.php b/src/GradientImage.php index b84d04a..2f7b2d9 100644 --- a/src/GradientImage.php +++ b/src/GradientImage.php @@ -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