Add (v1)
This commit is contained in:
@@ -4,13 +4,9 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\Facades\Image;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Intervention\Image\Facades\Image;
|
||||
|
||||
class ImageUploadController extends Controller
|
||||
{
|
||||
@@ -26,8 +22,8 @@ public function index(Request $request)
|
||||
|
||||
// Generate a unique filename for the uploaded file and LQIP version
|
||||
$uuid = Str::uuid()->toString();
|
||||
$fileName = time() . '_' . $uuid . '.jpg';
|
||||
$lqipFileName = time() . '_' . $uuid . '_lqip.jpg';
|
||||
$fileName = time().'_'.$uuid.'.jpg';
|
||||
$lqipFileName = time().'_'.$uuid.'_lqip.jpg';
|
||||
|
||||
// Convert the file to JPEG format using Intervention Image library
|
||||
$image = Image::make($file->getRealPath())->encode('jpg', 100);
|
||||
@@ -46,8 +42,8 @@ public function index(Request $request)
|
||||
$image->encode('jpg', 50);
|
||||
|
||||
// Save the processed image to the 'r2' storage driver under the 'uploads' directory
|
||||
$filePath = 'uploads/' . $fileName;
|
||||
$lqipFilePath = 'uploads/' . $lqipFileName;
|
||||
$filePath = 'uploads/'.$fileName;
|
||||
$lqipFilePath = 'uploads/'.$lqipFileName;
|
||||
Storage::disk('r2')->put($filePath, $image->stream()->detach());
|
||||
|
||||
// Save the original image to a temporary file and open it again
|
||||
@@ -56,7 +52,7 @@ public function index(Request $request)
|
||||
$clonedImage = Image::make($tempImagePath);
|
||||
|
||||
// Create the LQIP version of the image using a small size while maintaining the aspect ratio
|
||||
$lqipImage = $clonedImage->fit(10, 10, function ($constraint) use ($originalWidth, $originalHeight) {
|
||||
$lqipImage = $clonedImage->fit(10, 10, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
$lqipImage->encode('jpg', 5);
|
||||
|
||||
Reference in New Issue
Block a user