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.

28 lines
987 B

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