AipImageCensor.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /**
  19. * 黄反识别
  20. */
  21. class AipImageCensor extends AipBase{
  22. /**
  23. * @var string
  24. */
  25. private $imageCensorUserDefinedUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/v2/user_defined';
  26. /**
  27. * @var string
  28. */
  29. private $textCensorUserDefinedUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined';
  30. /**
  31. * @param string $image 图像
  32. * @return array
  33. */
  34. public function imageCensorUserDefined($image){
  35. $data = array();
  36. $isUrl = substr(trim($image), 0, 4) === 'http';
  37. if(!$isUrl){
  38. $data['image'] = base64_encode($image);
  39. }else{
  40. $data['imgUrl'] = $image;
  41. }
  42. return $this->request($this->imageCensorUserDefinedUrl, $data);
  43. }
  44. /**
  45. * @param string $text
  46. * @return array
  47. */
  48. public function textCensorUserDefined($text){
  49. $data = array();
  50. $data['text'] = $text;
  51. return $this->request($this->textCensorUserDefinedUrl, $data);
  52. }
  53. }