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.
 
 
 
 

95 lines
2.8 KiB

<?php
use App\Image\Processor;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Jcupitt\Vips\Image;
/*
|--------------------------------------------------------------------------
| 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) {
// && !isset($request->h)
if (isset($request->w) && isset($request->h)) {
$image = Image::thumbnail('../public/image.jpg', $request->w, ['height' => $request->h, 'crop' => 'centre']);
}
if (isset($request->w) && !isset($request->h)) {
$image = Image::thumbnail('../public/image.jpg', $request->w, ['height' => getimagesize('../public/image.jpg')[1]]);
}
if (!isset($request->w) && isset($request->h)) {
$image = Image::thumbnail('../public/image.jpg', getimagesize('../public/image.jpg')[0], ['height' => $request->h]);
}
$y = null;
$x = null;
if (isset($request->brightness) || isset($request->saturation)) {
$image = Processor::brightness($image, isset($request->brightness) ? $request->brightness : 1.0, isset($request->saturation) ? $request->saturation : 1.0);
}
if ($request->rotation) {
$image = $image->rotate($request->rotation);
}
// ----------------------------------------------------------------------------------------
if ($request->cpx) {
$GLOBALS['x'] = $request->cpx;
} else {
$GLOBALS['x'] = ($image->width - $request->w) / 2;
}
if ($request->cpy) {
$GLOBALS['y'] = $request->cpy;
} else {
$GLOBALS['y'] = ($image->height - $request->h) / 2;
}
if ($request->debug == true) {
if (!$request->cpx) {
$image = $image->draw_line(1000, $image->width / 2, 0, $image->width / 2, $image->height);
}
if (!$request->cpy) {
$image = $image->draw_line(1000, 0, $image->height / 2, $image->width, $image->height / 2);
}
if ($request->cpx) {
$image = $image->draw_line(1000, $request->cpx, 0, $request->cpx, $image->height);
}
if ($request->cpy) {
$image = $image->draw_line(1000, 0, $request->cpy, $image->width, $request->cpy);
}
}
// ----------------------------------------------------------------------------------------
if ($request->flip == "h") {
$image = $image->fliphor();
}
if ($request->flip == "v") {
$image = $image->flipver();
}
$image->writeToFile('image-modified.jpg', [
'Q' => $request->q
]);
return response()->file(public_path("image-modified.jpg"));
});