AipImageProcess.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /*
  3. * Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  6. * use this file except in compliance with the License. You may obtain a copy of
  7. * the License at
  8. *
  9. * Http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. require_once 'lib/AipBase.php';
  18. class AipImageProcess extends AipBase {
  19. /**
  20. * 图像无损放大 image_quality_enhance api url
  21. * @var string
  22. */
  23. private $imageQualityEnhanceUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/image_quality_enhance';
  24. /**
  25. * 图像去雾 dehaze api url
  26. * @var string
  27. */
  28. private $dehazeUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/dehaze';
  29. /**
  30. * 图像对比度增强 contrast_enhance api url
  31. * @var string
  32. */
  33. private $contrastEnhanceUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/contrast_enhance';
  34. /**
  35. * 图像无损放大接口
  36. *
  37. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  38. * @param array $options - 可选参数对象,key: value都为string类型
  39. * @description options列表:
  40. * @return array
  41. */
  42. public function imageQualityEnhance($image, $options=array()){
  43. $data = array();
  44. $data['image'] = base64_encode($image);
  45. $data = array_merge($data, $options);
  46. return $this->request($this->imageQualityEnhanceUrl, $data);
  47. }
  48. /**
  49. * 图像去雾接口
  50. *
  51. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  52. * @param array $options - 可选参数对象,key: value都为string类型
  53. * @description options列表:
  54. * @return array
  55. */
  56. public function dehaze($image, $options=array()){
  57. $data = array();
  58. $data['image'] = base64_encode($image);
  59. $data = array_merge($data, $options);
  60. return $this->request($this->dehazeUrl, $data);
  61. }
  62. /**
  63. * 图像对比度增强接口
  64. *
  65. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  66. * @param array $options - 可选参数对象,key: value都为string类型
  67. * @description options列表:
  68. * @return array
  69. */
  70. public function contrastEnhance($image, $options=array()){
  71. $data = array();
  72. $data['image'] = base64_encode($image);
  73. $data = array_merge($data, $options);
  74. return $this->request($this->contrastEnhanceUrl, $data);
  75. }
  76. }