You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

110 lines
3.5 KiB

<?php
use App\Http\Controllers\FileController;
use App\Image\Processor;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Jcupitt\Vips\Config;
use Jcupitt\Vips\Extend;
use Jcupitt\Vips\Image;
use Jcupitt\Vips\Utils;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function (Request $request) {
// // $request->dddd = 'tesst';
// dump($request->);
if (!isset($request->w) && !isset($request->h)) {
$image = Image::thumbnail('../public/image.png', getimagesize('../public/image.png')[0]);
}
if ($request->r) {
$rArray = explode(':', $request->r);
if (isset($request->w) && !isset($request->h)) {
$request->h = $request->w * $rArray[1];
$request->w = $request->w * $rArray[0];
}
if (!isset($request->w) && isset($request->h)) {
$request->h = $request->h * $rArray[1];
$request->w = $request->h * $rArray[0];
}
if (!isset($request->w) && !isset($request->h)) {
$request->h = getimagesize('../public/image.png')[0] * $rArray[1];
$request->w = getimagesize('../public/image.png')[0] * $rArray[0];
}
}
if (isset($request->w) && !isset($request->h)) {
$image = Image::thumbnail('../public/image.png', $request->w, ['height' => getimagesize('../public/image.png')[1]]);
}
if (!isset($request->w) && isset($request->h)) {
$image = Image::thumbnail('../public/image.png', getimagesize('../public/image.png')[0], ['height' => $request->h]);
}
if (isset($request->w) && isset($request->h) && !($request->canv == true)) {
$image = Image::thumbnail('../public/image.png', $request->w, ['height' => $request->h, 'crop' => 'centre']);
}
if (isset($request->w) && isset($request->h) && $request->canv == true) {
$image = Image::thumbnail('../public/image.png', $request->w, ['height' => $request->h]);
$widthH = ($request->h - $image->height) / 2;
$widthW = ($request->w - $image->width) / 2;
$image = $image->embed(
$widthW,
$widthH,
$request->w,
$request->h,
['extend' => 'background','background'=>1024]
);
}
if (isset($request->brightness) || isset($request->saturation) || isset($request->hue)) {
$image = Processor::brightness($image, isset($request->brightness) ? $request->brightness : 1.0, isset($request->saturation) ? $request->saturation : 1.0, isset($request->hue) ? $request->hue : 0.0);
}
if ($request->rotation) {
$image = $image->rotate($request->rotation);
}
if ($request->flip == "h") {
$image = $image->fliphor();
}
if ($request->flip == "v") {
$image = $image->flipver();
}
if ($request->flip == "hv") {
$image = $image->fliphor();
$image = $image->flipver();
}
$image->writeToFile('image-modified.webp', [
'Q' => isset($request->q) ? $request->q : 100
]);
return response()->file(public_path("image-modified.webp" . $request->ext));
});
Route::get('/upload',function(){
return view('welcome');
});
Route::post('/upload',[FileController::class,'store']);