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.

30 lines
996 B

  1. <?php
  2. namespace App\Image\Traits;
  3. use Jcupitt\Vips\Interpretation;
  4. trait ModulateTrait {
  5. public function brightness($image, float $brightness = 1.0, float $saturation = 1.0, float $hue = 0.0)
  6. {
  7. $oldInterpretation = $image->interpretation;
  8. $hue %= 360;
  9. if ($hue < 0) {
  10. $hue = 360 + $hue;
  11. }
  12. if ($image->hasAlpha()) {
  13. $imageWithoutAlpha = $image->extract_band(0, ['n' => $image->bands - 1]);
  14. $alpha = $image->extract_band($image->bands - 1, ['n' => 1]);
  15. return $imageWithoutAlpha
  16. ->colourspace(Interpretation::LCH)
  17. ->linear([$brightness, $saturation, 1.0], [0.0, 0.0, $hue])
  18. ->colourspace($oldInterpretation)
  19. ->bandjoin($alpha);
  20. }
  21. return $image
  22. ->colourspace(Interpretation::LCH)
  23. ->linear([$brightness, $saturation, 1.0], [0.0, 0.0, $hue])
  24. ->colourspace($oldInterpretation);
  25. }
  26. }