AipImageProcess.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. * 黑白图像上色 colourize api url
  36. * @var string
  37. */
  38. private $colourizeUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/colourize';
  39. /**
  40. * 拉伸图像恢复 stretch_restore api url
  41. * @var string
  42. */
  43. private $stretchRestoreUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/stretch_restore';
  44. /**
  45. * 风格转换
  46. * @var string
  47. */
  48. private $styleTrans = "https://aip.baidubce.com/rest/2.0/image-process/v1/style_trans";
  49. /**
  50. * 图像修复
  51. * @var string
  52. */
  53. private $inpainting = "https://aip.baidubce.com/rest/2.0/image-process/v1/inpainting";
  54. /**
  55. * 图像清晰度增强
  56. * @var string
  57. */
  58. private $imageDefinitionEnhance = "https://aip.baidubce.com/rest/2.0/image-process/v1/image_definition_enhance";
  59. /**
  60. *人像动漫化
  61. * @var string
  62. */
  63. private $selfieAnime = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime";
  64. /**
  65. * 天空分割
  66. * @var string
  67. */
  68. private $skySeg = "https://aip.baidubce.com/rest/2.0/image-process/v1/sky_seg";
  69. /**
  70. * 图像无损放大接口
  71. *
  72. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  73. * @param array $options - 可选参数对象,key: value都为string类型
  74. * @description options列表:
  75. * @return array
  76. */
  77. public function imageQualityEnhance($image, $options=array()){
  78. $data = array();
  79. $data['image'] = base64_encode($image);
  80. $data = array_merge($data, $options);
  81. return $this->request($this->imageQualityEnhanceUrl, $data);
  82. }
  83. /**
  84. * 图像去雾接口
  85. *
  86. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  87. * @param array $options - 可选参数对象,key: value都为string类型
  88. * @description options列表:
  89. * @return array
  90. */
  91. public function dehaze($image, $options=array()){
  92. $data = array();
  93. $data['image'] = base64_encode($image);
  94. $data = array_merge($data, $options);
  95. return $this->request($this->dehazeUrl, $data);
  96. }
  97. /**
  98. * 图像对比度增强接口
  99. *
  100. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  101. * @param array $options - 可选参数对象,key: value都为string类型
  102. * @description options列表:
  103. * @return array
  104. */
  105. public function contrastEnhance($image, $options=array()){
  106. $data = array();
  107. $data['image'] = base64_encode($image);
  108. $data = array_merge($data, $options);
  109. return $this->request($this->contrastEnhanceUrl, $data);
  110. }
  111. /**
  112. * 黑白图像上色接口
  113. *
  114. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  115. * @param array $options - 可选参数对象,key: value都为string类型
  116. * @description options列表:
  117. * @return array
  118. */
  119. public function colourize($image, $options=array()){
  120. $data = array();
  121. $data['image'] = base64_encode($image);
  122. $data = array_merge($data, $options);
  123. return $this->request($this->colourizeUrl, $data);
  124. }
  125. /**
  126. * 拉伸图像恢复接口
  127. *
  128. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  129. * @param array $options - 可选参数对象,key: value都为string类型
  130. * @description options列表:
  131. * @return array
  132. */
  133. public function stretchRestore($image, $options=array()){
  134. $data = array();
  135. $data['image'] = base64_encode($image);
  136. $data = array_merge($data, $options);
  137. return $this->request($this->stretchRestoreUrl, $data);
  138. }
  139. /**
  140. * 人像动漫化
  141. *
  142. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  143. * @param array $options - 可选参数对象,key: value都为string类型
  144. * @description options列表:
  145. * @return array
  146. */
  147. public function selfieAnime($image, $options=array()){
  148. $data = array();
  149. $data['image'] = base64_encode($image);
  150. $data = array_merge($data, $options);
  151. return $this->request($this->selfieAnime, $data);
  152. }
  153. /**
  154. * 图像清晰度增强
  155. *
  156. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  157. * @param array $options - 可选参数对象,key: value都为string类型
  158. * @description options列表:
  159. * @return array
  160. */
  161. public function imageDefinitionEnhance($image, $options=array()){
  162. $data = array();
  163. $data['image'] = base64_encode($image);
  164. $data = array_merge($data, $options);
  165. return $this->request($this->imageDefinitionEnhance, $data);
  166. }
  167. /**
  168. * 图像风格转换
  169. *
  170. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  171. * @param array $options - 可选参数对象,key: value都为string类型
  172. * @description options列表:
  173. * @return array
  174. */
  175. public function styleTrans($image, $options=array()){
  176. $data = array();
  177. $data['image'] = base64_encode($image);
  178. $data = array_merge($data, $options);
  179. return $this->request($this->styleTrans, $data);
  180. }
  181. /**
  182. * 天空分割
  183. *
  184. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  185. * @param array $options - 可选参数对象,key: value都为string类型
  186. * @description options列表:
  187. * @return array
  188. */
  189. public function skySeg($image, $options=array()){
  190. $data = array();
  191. $data['image'] = base64_encode($image);
  192. $data = array_merge($data, $options);
  193. return $this->request($this->skySeg, $data);
  194. }
  195. /**
  196. * 图像修复
  197. *
  198. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  199. * @param array $options - 可选参数对象,key: value都为string类型
  200. * @description options列表:
  201. * @return array
  202. */
  203. public function inpaintingByMask($image, $rectangle, $options=array()){
  204. $data = array();
  205. $data['image'] = base64_encode($image);
  206. $data['rectangle'] = $rectangle;
  207. $data = array_merge($data, $options);
  208. return $this->request($this->inpainting, $data);
  209. }
  210. }