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.

99 lines
3.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 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.png', getimagesize('../public/image.png')[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. if (!isset($request->w) && !isset($request->h)) {
  34. $request->h = getimagesize('../public/image.png')[0] * $rArray[1];
  35. $request->w = getimagesize('../public/image.png')[0] * $rArray[0];
  36. }
  37. }
  38. if (isset($request->w) && !isset($request->h)) {
  39. $image = Image::thumbnail('../public/image.png', $request->w, ['height' => getimagesize('../public/image.png')[1]]);
  40. }
  41. if (!isset($request->w) && isset($request->h)) {
  42. $image = Image::thumbnail('../public/image.png', getimagesize('../public/image.png')[0], ['height' => $request->h]);
  43. }
  44. if (isset($request->w) && isset($request->h) && !($request->canv == true)) {
  45. $image = Image::thumbnail('../public/image.png', $request->w, ['height' => $request->h, 'crop' => 'centre']);
  46. }
  47. if (isset($request->w) && isset($request->h) && $request->canv == true) {
  48. $image = Image::thumbnail('../public/image.png', $request->w, ['height' => $request->h]);
  49. $widthH = ($request->h - $image->height) / 2;
  50. $widthW = ($request->w - $image->width) / 2;
  51. $image = $image->embed(
  52. $widthW,
  53. $widthH,
  54. $request->w,
  55. $request->h,
  56. ['extend' => 'white']
  57. );
  58. }
  59. if (isset($request->brightness) || isset($request->saturation) || isset($request->hue)) {
  60. $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);
  61. }
  62. if ($request->rotation) {
  63. $image = $image->rotate($request->rotation);
  64. }
  65. if ($request->flip == "h") {
  66. $image = $image->fliphor();
  67. }
  68. if ($request->flip == "v") {
  69. $image = $image->flipver();
  70. }
  71. if ($request->flip == "hv") {
  72. $image = $image->fliphor();
  73. $image = $image->flipver();
  74. }
  75. $image->writeToFile('image-modified.' . $request->ext, [
  76. 'Q' => isset($request->q) ? $request->q : 100
  77. ]);
  78. return response()->file(public_path("image-modified." . $request->ext));
  79. });