SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/QualityImageTransform.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16.  
  17. /**
  18. * Sets the image quality for JPEGs.
  19. * If you don't use one of these, the default is 95
  20. **/
  21. class QualityImageTransform implements ImageTransform
  22. {
  23. private $q;
  24.  
  25.  
  26. /**
  27.   * @param int $q The quality to use, 1 = worst, 100 = best.
  28.   **/
  29. public function __construct($q)
  30. {
  31. $this->q = $q;
  32. }
  33.  
  34.  
  35. /**
  36.   * Does the actual transform
  37.   *
  38.   * @param Image $img The image to transform
  39.   **/
  40. public function transform(Image $img)
  41. {
  42. $img->quality($this->q);
  43. return true;
  44. }
  45.  
  46.  
  47. /**
  48.   * Estimate the RAM requirement to run this transform
  49.   *
  50.   * @return int Bytes
  51.   **/
  52. function estimateRamRequirement()
  53. {
  54. return 0;
  55. }
  56.  
  57. }
  58.  
  59.  
  60.