ImageViewTemplate.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Qcloud\Cos\ImageParamTemplate;
  3. /**
  4. * Parses default XML exception responses
  5. */
  6. class ImageViewTemplate extends ImageTemplate
  7. {
  8. private $mode;
  9. private $width;
  10. private $height;
  11. private $format;
  12. private $quality;
  13. public function __construct() {
  14. parent::__construct();
  15. $this->mode = "";
  16. $this->width = "";
  17. $this->height = "";
  18. $this->format = "";
  19. $this->quality = "";
  20. }
  21. public function setMode($value) {
  22. $this->mode = "/" . $value;
  23. }
  24. public function setWidth($value) {
  25. $this->width = "/w/" . $value;
  26. }
  27. public function setHeight($value) {
  28. $this->height = "/h/" . $value;
  29. }
  30. public function setFormat($value) {
  31. $this->format = "/format/" . $value;
  32. }
  33. public function setQuality($qualityType, $qualityValue, $force = 0) {
  34. if($qualityType == 1){
  35. $this->quality = "/q/$qualityValue" ;
  36. if($force){
  37. $this->quality .= "!";
  38. }
  39. }else if($qualityType == 2){
  40. $this->quality = "/rq/$qualityValue" ;
  41. }else if ($qualityType == 3){
  42. $this->quality = "/lq/$qualityValue" ;
  43. }
  44. }
  45. public function getMode() {
  46. return $this->mode;
  47. }
  48. public function getWidth() {
  49. return $this->width;
  50. }
  51. public function getHeight() {
  52. return $this->height;
  53. }
  54. public function getFormat() {
  55. return $this->format;
  56. }
  57. public function getQuality() {
  58. return $this->quality;
  59. }
  60. public function queryString() {
  61. $head = "imageView2";
  62. $res = "";
  63. if($this->mode) {
  64. $res .= $this->mode;
  65. }
  66. if($this->width) {
  67. $res .= $this->width;
  68. }
  69. if($this->height) {
  70. $res .= $this->height;
  71. }
  72. if($this->format) {
  73. $res .= $this->format;
  74. }
  75. if($this->quality) {
  76. $res .= $this->quality;
  77. }
  78. if($res) {
  79. $res = $head . $res;
  80. }
  81. return $res;
  82. }
  83. public function resetRule() {
  84. $this->mode = "";
  85. $this->width = "";
  86. $this->height = "";
  87. $this->format = "";
  88. $this->quality = "";
  89. }
  90. }