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