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

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\Image;
  6. /*
  7. |--------------------------------------------------------------------------
  8. | Web Routes
  9. |--------------------------------------------------------------------------
  10. |
  11. | Here is where you can register web routes for your application. These
  12. | routes are loaded by the RouteServiceProvider within a group which
  13. | contains the "web" middleware group. Now create something great!
  14. |
  15. */
  16. Route::get('/', function (Request $request) {
  17. // && !isset($request->h)
  18. if (isset($request->w) && isset($request->h)) {
  19. $image = Image::thumbnail('../public/image.jpg', $request->w, ['height' => $request->h, 'crop' => 'centre']);
  20. }
  21. if (isset($request->w) && !isset($request->h)) {
  22. $image = Image::thumbnail('../public/image.jpg', $request->w, ['height' => getimagesize('../public/image.jpg')[1]]);
  23. }
  24. if (!isset($request->w) && isset($request->h)) {
  25. $image = Image::thumbnail('../public/image.jpg', getimagesize('../public/image.jpg')[0], ['height' => $request->h]);
  26. }
  27. $y = null;
  28. $x = null;
  29. if (isset($request->brightness) || isset($request->saturation)) {
  30. $image = Processor::brightness($image, isset($request->brightness) ? $request->brightness : 1.0, isset($request->saturation) ? $request->saturation : 1.0);
  31. }
  32. if ($request->rotation) {
  33. $image = $image->rotate($request->rotation);
  34. }
  35. // ----------------------------------------------------------------------------------------
  36. if ($request->cpx) {
  37. $GLOBALS['x'] = $request->cpx;
  38. } else {
  39. $GLOBALS['x'] = ($image->width - $request->w) / 2;
  40. }
  41. if ($request->cpy) {
  42. $GLOBALS['y'] = $request->cpy;
  43. } else {
  44. $GLOBALS['y'] = ($image->height - $request->h) / 2;
  45. }
  46. if ($request->debug == true) {
  47. if (!$request->cpx) {
  48. $image = $image->draw_line(1000, $image->width / 2, 0, $image->width / 2, $image->height);
  49. }
  50. if (!$request->cpy) {
  51. $image = $image->draw_line(1000, 0, $image->height / 2, $image->width, $image->height / 2);
  52. }
  53. if ($request->cpx) {
  54. $image = $image->draw_line(1000, $request->cpx, 0, $request->cpx, $image->height);
  55. }
  56. if ($request->cpy) {
  57. $image = $image->draw_line(1000, 0, $request->cpy, $image->width, $request->cpy);
  58. }
  59. }
  60. // ----------------------------------------------------------------------------------------
  61. if ($request->flip == "h") {
  62. $image = $image->fliphor();
  63. }
  64. if ($request->flip == "v") {
  65. $image = $image->flipver();
  66. }
  67. $image->writeToFile('image-modified.jpg', [
  68. 'Q' => $request->q
  69. ]);
  70. return response()->file(public_path("image-modified.jpg"));
  71. });