return uploaded file when generating image
This commit is contained in:
parent
e00bdc1277
commit
199be4dc4d
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue