ImageViewTemplate.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. private $ignoreError;
  14. public function __construct() {
  15. parent::__construct();
  16. $this->mode = "";
  17. $this->width = "";
  18. $this->height = "";
  19. $this->format = "";
  20. $this->quality = "";
  21. $this->ignoreError = "";
  22. }
  23. public function setMode($value) {
  24. $this->mode = "/" . $value;
  25. }
  26. public function setWidth($value) {
  27. $this->width = "/w/" . $value;
  28. }
  29. public function setHeight($value) {
  30. $this->height = "/h/" . $value;
  31. }
  32. public function setFormat($value) {
  33. $this->format = "/format/" . $value;
  34. }
  35. public function setQuality($qualityType, $qualityValue, $force = 0) {
  36. if($qualityType == 1){
  37. $this->quality = "/q/$qualityValue" ;
  38. if($force){
  39. $this->quality .= "!";
  40. }
  41. }else if($qualityType == 2){
  42. $this->quality = "/rq/$qualityValue" ;
  43. }else if ($qualityType == 3){
  44. $this->quality = "/lq/$qualityValue" ;
  45. }
  46. }
  47. public function ignoreError() {
  48. $this->ignoreError = '/ignore-error/1';
  49. }
  50. public function getMode() {
  51. return $this->mode;
  52. }
  53. public function getWidth() {
  54. return $this->width;
  55. }
  56. public function getHeight() {
  57. return $this->height;
  58. }
  59. public function getFormat() {
  60. return $this->format;
  61. }
  62. public function getQuality() {
  63. return $this->quality;
  64. }
  65. public function queryString() {
  66. $head = "imageView2";
  67. $res = "";
  68. if($this->mode) {
  69. $res .= $this->mode;
  70. }
  71. if($this->width) {
  72. $res .= $this->width;
  73. }
  74. if($this->height) {
  75. $res .= $this->height;
  76. }
  77. if($this->format) {
  78. $res .= $this->format;
  79. }
  80. if($this->quality) {
  81. $res .= $this->quality;
  82. }
  83. if($this->ignoreError) {
  84. $res .= $this->ignoreError;
  85. }
  86. if($res) {
  87. $res = $head . $res;
  88. }
  89. return $res;
  90. }
  91. public function resetRule() {
  92. $this->mode = "";
  93. $this->width = "";
  94. $this->height = "";
  95. $this->format = "";
  96. $this->quality = "";
  97. }
  98. }