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

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <?php
  2. use App\Http\Controllers\FileController;
  3. use App\Image\Processor;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Route;
  6. use Jcupitt\Vips\Config;
  7. use Jcupitt\Vips\Extend;
  8. use Jcupitt\Vips\Image;
  9. use Jcupitt\Vips\Utils;
  10. /*
  11. |--------------------------------------------------------------------------
  12. | Web Routes
  13. |--------------------------------------------------------------------------
  14. |
  15. | Here is where you can register web routes for your application. These
  16. | routes are loaded by the RouteServiceProvider within a group which
  17. | contains the "web" middleware group. Now create something great!
  18. |
  19. */
  20. Route::get('/', function (Request $request) {
  21. // // $request->dddd = 'tesst';
  22. // dump($request->);
  23. if (!isset($request->w) && !isset($request->h)) {
  24. $image = Image::thumbnail('../public/image.png', getimagesize('../public/image.png')[0]);
  25. }
  26. if ($request->r) {
  27. $rArray = explode(':', $request->r);
  28. if (isset($request->w) && !isset($request->h)) {
  29. $request->h = $request->w * $rArray[1];
  30. $request->w = $request->w * $rArray[0];
  31. }
  32. if (!isset($request->w) && isset($request->h)) {
  33. $request->h = $request->h * $rArray[1];
  34. $request->w = $request->h * $rArray[0];
  35. }
  36. if (!isset($request->w) && !isset($request->h)) {
  37. $request->h = getimagesize('../public/image.png')[0] * $rArray[1];
  38. $request->w = getimagesize('../public/image.png')[0] * $rArray[0];
  39. }
  40. }
  41. if (isset($request->w) && !isset($request->h)) {
  42. $image = Image::thumbnail('../public/image.png', $request->w, ['height' => getimagesize('../public/image.png')[1]]);
  43. }
  44. if (!isset($request->w) && isset($request->h)) {
  45. $image = Image::thumbnail('../public/image.png', getimagesize('../public/image.png')[0], ['height' => $request->h]);
  46. }
  47. if (isset($request->w) && isset($request->h) && !($request->canv == true)) {
  48. $image = Image::thumbnail('../public/image.png', $request->w, ['height' => $request->h, 'crop' => 'centre']);
  49. }
  50. if (isset($request->w) && isset($request->h) && $request->canv == true) {
  51. $image = Image::thumbnail('../public/image.png', $request->w, ['height' => $request->h]);
  52. $widthH = ($request->h - $image->height) / 2;
  53. $widthW = ($request->w - $image->width) / 2;
  54. $image = $image->embed(
  55. $widthW,
  56. $widthH,
  57. $request->w,
  58. $request->h,
  59. ['extend' => 'background','background'=>1024]
  60. );
  61. }
  62. if (isset($request->brightness) || isset($request->saturation) || isset($request->hue)) {
  63. $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);
  64. }
  65. if ($request->rotation) {
  66. $image = $image->rotate($request->rotation);
  67. }
  68. if ($request->flip == "h") {
  69. $image = $image->fliphor();
  70. }
  71. if ($request->flip == "v") {
  72. $image = $image->flipver();
  73. }
  74. if ($request->flip == "hv") {
  75. $image = $image->fliphor();
  76. $image = $image->flipver();
  77. }
  78. $image->writeToFile('image-modified.webp', [
  79. 'Q' => isset($request->q) ? $request->q : 100
  80. ]);
  81. return response()->file(public_path("image-modified.webp" . $request->ext));
  82. });
  83. Route::get('/upload',function(){
  84. return view('welcome');
  85. });
  86. Route::post('/upload',[FileController::class,'store']);