|
@ -3,6 +3,7 @@ |
|
|
use App\Image\Processor; |
|
|
use App\Image\Processor; |
|
|
use Illuminate\Http\Request; |
|
|
use Illuminate\Http\Request; |
|
|
use Illuminate\Support\Facades\Route; |
|
|
use Illuminate\Support\Facades\Route; |
|
|
|
|
|
use Jcupitt\Vips\Extend; |
|
|
use Jcupitt\Vips\Image; |
|
|
use Jcupitt\Vips\Image; |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
@ -16,11 +17,28 @@ use Jcupitt\Vips\Image; |
|
|
| |
|
|
| |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
Route::get('/', function (Request $request) { |
|
|
|
|
|
|
|
|
Route::get('/image.{ext}', 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']); |
|
|
|
|
|
|
|
|
// // $request->dddd = 'tesst';
|
|
|
|
|
|
// dump($request->);
|
|
|
|
|
|
|
|
|
|
|
|
if (!isset($request->w) && !isset($request->h)) { |
|
|
|
|
|
$image = Image::thumbnail('../public/image.jpg', getimagesize('../public/image.jpg')[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)) { |
|
|
if (isset($request->w) && !isset($request->h)) { |
|
@ -31,51 +49,30 @@ Route::get('/', function (Request $request) { |
|
|
$image = Image::thumbnail('../public/image.jpg', getimagesize('../public/image.jpg')[0], ['height' => $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 (isset($request->w) && isset($request->h) && !($request->canv == true)) { |
|
|
|
|
|
$image = Image::thumbnail('../public/image.jpg', $request->w, ['height' => $request->h, 'crop' => 'centre']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------
|
|
|
|
|
|
if ($request->cpx) { |
|
|
|
|
|
$GLOBALS['x'] = $request->cpx; |
|
|
|
|
|
} else { |
|
|
|
|
|
$GLOBALS['x'] = ($image->width - $request->w) / 2; |
|
|
|
|
|
|
|
|
if (isset($request->w) && isset($request->h) && $request->canv == true) { |
|
|
|
|
|
$image = Image::thumbnail('../public/image.jpg', $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' => 'white'] |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($request->cpy) { |
|
|
|
|
|
$GLOBALS['y'] = $request->cpy; |
|
|
|
|
|
} else { |
|
|
|
|
|
$GLOBALS['y'] = ($image->height - $request->h) / 2; |
|
|
|
|
|
|
|
|
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->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->rotation) { |
|
|
|
|
|
$image = $image->rotate($request->rotation); |
|
|
} |
|
|
} |
|
|
// ----------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
if ($request->flip == "h") { |
|
|
if ($request->flip == "h") { |
|
|
$image = $image->fliphor(); |
|
|
$image = $image->fliphor(); |
|
@ -85,11 +82,14 @@ Route::get('/', function (Request $request) { |
|
|
$image = $image->flipver(); |
|
|
$image = $image->flipver(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($request->flip == "hv") { |
|
|
|
|
|
$image = $image->fliphor(); |
|
|
|
|
|
$image = $image->flipver(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$image->writeToFile('image-modified.jpg', [ |
|
|
|
|
|
|
|
|
$image->writeToFile('image-modified.' . $request->ext, [ |
|
|
'Q' => $request->q |
|
|
'Q' => $request->q |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
return response()->file(public_path("image-modified.jpg")); |
|
|
|
|
|
|
|
|
return response()->file(public_path("image-modified." . $request->ext)); |
|
|
}); |
|
|
}); |