picProcess.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. const COS = require('../lib/cos-wx-sdk-v5');
  2. var wxfs = wx.getFileSystemManager();
  3. const config = require('../config');
  4. const { cos, requestCallback } = require('../tools');
  5. const picProcessDao = {
  6. 'uploadImg 上传时使用图片处理': uploadImg,
  7. 'requestImg 对云上数据进行图片处理': requestImg,
  8. 'getImg 下载时使用图片处理': getImg,
  9. '生成带图片处理参数的签名 URL': getObjectUrlWithPicProcess,
  10. '开通原图保护 openOriginProtect': openOriginProtect,
  11. '查询原图保护 describeOriginProtect': describeOriginProtect,
  12. '关闭原图保护 closeOriginProtect': closeOriginProtect,
  13. '查询海报合成任务 describePosterProductionJob': describePosterProductionJob,
  14. '批量拉取海报合成任务 describePosterProductionJobList': describePosterProductionJobList,
  15. '取消海报合成任务 cancelPosterProductionJob': cancelPosterProductionJob,
  16. '提交海报合成任务 postPosterProductionJob': postPosterProductionJob,
  17. '查询海报合成模板 describePosterProductionTemplate': describePosterProductionTemplate,
  18. '查询海报合成模板列表 describePosterProductionTemplateList': describePosterProductionTemplateList,
  19. '删除海报合成模板 deletePosterProductionTemplate': deletePosterProductionTemplate,
  20. '上传海报合成模板 uploadPosterProductionTemplate': uploadPosterProductionTemplate,
  21. '开通 Guetzli 压缩 openImageGuetzli': openImageGuetzli,
  22. '查询 Guetzli 压缩 describeImageGuetzli': describeImageGuetzli,
  23. '关闭 Guetzli 压缩 closeImageGuetzli': closeImageGuetzli,
  24. '提交图片处理任务 createImageProcessJob': createImageProcessJob,
  25. '创建图片处理模板 createImageProcessTemplate': createImageProcessTemplate,
  26. '更新图片处理模板 updateImageProcessTemplate': updateImageProcessTemplate,
  27. '新增图片样式 addImageStyle': addImageStyle,
  28. '查询图片样式 describeImageStyles': describeImageStyles,
  29. '删除图片样式 deleteImageStyles': deleteImageStyles,
  30. '异常图片检测同步请求 imageInspectSync': imageInspectSync,
  31. '创建异常图片检测任务 createImageInspectJob': createImageInspectJob,
  32. '开通图片处理异步服务 openImageProcessService': openImageProcessService,
  33. '查询图片处理异步服务 describeImageProcessService': describeImageProcessService,
  34. '关闭图片处理异步服务 closeImageProcessService': closeImageProcessService,
  35. '查询图片处理异步队列 describeImageProcessQueue': describeImageProcessQueue,
  36. '更新图片处理异步队列 updateImageProcessQueue': updateImageProcessQueue,
  37. '开通极智压缩 openImageSlim': openImageSlim,
  38. '查询极智压缩状态 describeImageSlim': describeImageSlim,
  39. '关闭极智压缩 closeImageSlim': closeImageSlim,
  40. '通过API使用极智压缩 imageSlim': imageSlim,
  41. '获取原图 getOriginImage': getOriginImage,
  42. 'uploadImgAnimate 上传时合成动图': uploadImgAnimate,
  43. 'requestImgAnimate 对云上数据进行合成动图': requestImgAnimate,
  44. 'getImgAnimate 下载时使用合成动图': getImgAnimate,
  45. 'uploadImgWatermark 上传时使用图片水印': uploadImgWatermark,
  46. 'requestImgWatermark 对云上数据使用图片水印': requestImgWatermark,
  47. 'getImgWatermark 下载时使用图片水印': getImgWatermark,
  48. 'uploadImgWatermarkText 上传时使用文字水印': uploadImgWatermarkText,
  49. 'requestImgWatermarkText 对云上数据使用文字水印': requestImgWatermarkText,
  50. 'getImgWatermarkText 下载时使用文字水印': getImgWatermarkText,
  51. 'uploadImgCompress 上传时使用图片压缩': uploadImgCompress,
  52. 'requestImgCompress 对云上数据使用图片压缩': requestImgCompress,
  53. 'getImgCompress 下载时使用图片压缩': getImgCompress,
  54. };
  55. function uploadImg() {
  56. wx.chooseMessageFile({
  57. count: 10,
  58. type: 'all',
  59. success: function (res) {
  60. var file = res.tempFiles[0];
  61. wxfs.readFile({
  62. filePath: file.path,
  63. success: function (res) {
  64. cos.putObject(
  65. {
  66. Bucket: config.Bucket, // Bucket 格式:test-1250000000
  67. Region: config.Region,
  68. Key: file.name,
  69. Body: res.data,
  70. Headers: {
  71. // 通过 imageMogr2 接口使用图片缩放功能:指定图片宽度为 200,宽度等比压缩
  72. 'Pic-Operations':
  73. '{"is_pic_info": 1, "rules": [{"fileid": "desample_photo.jpg", "rule": "imageMogr2/thumbnail/200x/"}]}',
  74. },
  75. },
  76. requestCallback
  77. );
  78. },
  79. fail: (err) => console.error(err),
  80. });
  81. },
  82. fail: (err) => console.error(err),
  83. });
  84. }
  85. function requestImg() {
  86. cos.request(
  87. {
  88. Bucket: config.Bucket,
  89. Region: config.Region,
  90. Key: 'photo.png',
  91. Method: 'POST',
  92. Action: 'image_process',
  93. Headers: {
  94. // 通过 imageMogr2 接口使用图片缩放功能:指定图片宽度为 200,宽度等比压缩
  95. 'Pic-Operations':
  96. '{"is_pic_info": 1, "rules": [{"fileid": "desample_photo.jpg", "rule": "imageMogr2/thumbnail/200x/"}]}',
  97. },
  98. },
  99. requestCallback
  100. );
  101. }
  102. function getImg() {
  103. cos.getObject(
  104. {
  105. Bucket: config.Bucket,
  106. Region: config.Region,
  107. Key: '1.png',
  108. QueryString: `imageMogr2/thumbnail/200x/`,
  109. },
  110. requestCallback
  111. );
  112. }
  113. function getObjectUrlWithPicProcess() {
  114. // 生成带图片处理参数的文件签名URL,过期时间设置为 30 分钟。
  115. cos.getObjectUrl(
  116. {
  117. Bucket: config.Bucket,
  118. Region: config.Region,
  119. Key: 'photo.png',
  120. QueryString: `imageMogr2/thumbnail/200x/`,
  121. Expires: 1800,
  122. Sign: true,
  123. },
  124. (err, data) => {
  125. console.log('带签名', err || data);
  126. }
  127. );
  128. // 生成带图片处理参数的文件URL,不带签名。
  129. cos.getObjectUrl(
  130. {
  131. Bucket: config.Bucket,
  132. Region: config.Region,
  133. Key: 'photo.png',
  134. QueryString: `imageMogr2/thumbnail/200x/`,
  135. Sign: false,
  136. },
  137. (err, data) => {
  138. console.log('不带签名', err || data);
  139. }
  140. );
  141. }
  142. function openOriginProtect() {
  143. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  144. const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?origin-protect';
  145. const url = 'https://' + host;
  146. cos.request(
  147. {
  148. Method: 'PUT',
  149. Url: url,
  150. },
  151. function (err, data) {
  152. if (err) {
  153. // 处理请求失败
  154. console.log(err);
  155. } else {
  156. // 处理请求成功
  157. console.log(data.Response);
  158. }
  159. }
  160. );
  161. }
  162. function describeOriginProtect() {
  163. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  164. const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?origin-protect';
  165. const url = 'https://' + host;
  166. cos.request(
  167. {
  168. Method: 'GET',
  169. Url: url,
  170. },
  171. function (err, data) {
  172. if (err) {
  173. // 处理请求失败
  174. console.log(err);
  175. } else {
  176. // 处理请求成功
  177. console.log(data.Response);
  178. }
  179. }
  180. );
  181. }
  182. function closeOriginProtect() {
  183. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  184. const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?origin-protect';
  185. const url = 'https://' + host;
  186. cos.request(
  187. {
  188. Method: 'DELETE',
  189. Url: url,
  190. },
  191. function (err, data) {
  192. if (err) {
  193. // 处理请求失败
  194. console.log(err);
  195. } else {
  196. // 处理请求成功
  197. console.log(data.Response);
  198. }
  199. }
  200. );
  201. }
  202. function describePosterProductionJob() {
  203. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  204. const jobId = 'xxx';
  205. const key = `pic_jobs/${jobId}`; // jobId:{jobId};
  206. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  207. const url = `https://${host}/${key}`;
  208. cos.request(
  209. {
  210. Method: 'GET', // 固定值,必须
  211. Key: key, // 必须
  212. Url: url, // 请求的url,必须
  213. },
  214. function (err, data) {
  215. if (err) {
  216. // 处理请求失败
  217. console.log(err);
  218. } else {
  219. // 处理请求成功
  220. console.log(data.Response);
  221. }
  222. }
  223. );
  224. }
  225. function describePosterProductionJobList() {
  226. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  227. const key = `pic_jobs`; //
  228. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  229. const url = `https://${host}/${key}`;
  230. cos.request(
  231. {
  232. Method: 'GET', // 固定值,必须
  233. Key: key, // 必须
  234. Url: url, // 请求的url,必须
  235. Query: {
  236. // 拉取该队列 ID 下的任务;是否必传:是
  237. queueId: 'xxx',
  238. // 任务的 Tag;是否必传:是
  239. tag: 'PosterProduction',
  240. // 触发该任务的工作流ID;是否必传:否
  241. workflowId: '',
  242. // 触发该任务的存量触发任务ID;是否必传:否
  243. inventoryTriggerJobId: '',
  244. // 该任务的输入文件名,暂仅支持精确匹配;是否必传:否
  245. inputObject: '',
  246. // Desc 或者 Asc。默认为 Desc;是否必传:否
  247. orderByTime: 'Desc',
  248. // 请求的上下文,用于翻页。上次返回的值;是否必传:否
  249. nextToken: '',
  250. // 拉取该状态的任务,以,分割,支持多状态:All、Submitted、Running、Success、Failed、Pause、Cancel。默认为 All;是否必传:否
  251. states: 'All',
  252. // 拉取创建时间大于该时间的任务。格式为:%Y-%m-%dT%H:%m:%S%z,示例:2001-01-01T00:00:00+0800;是否必传:否
  253. // startCreationTime: "",
  254. // 拉取创建时间小于该时间的任务。格式为:%Y-%m-%dT%H:%m:%S%z,示例:2001-01-01T23:59:59+0800;是否必传:否
  255. // endCreationTime: "",
  256. },
  257. },
  258. function (err, data) {
  259. if (err) {
  260. // 处理请求失败
  261. console.log(err);
  262. } else {
  263. // 处理请求成功
  264. console.log(data.Response);
  265. }
  266. }
  267. );
  268. }
  269. function cancelPosterProductionJob() {
  270. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  271. const jobId = 'xxx';
  272. const key = `jobs/${jobId}?cancel`; // jobId:{jobId};
  273. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  274. const url = `https://${host}/${key}`;
  275. cos.request(
  276. {
  277. Method: 'PUT', // 固定值,必须
  278. Key: key, // 必须
  279. Url: url, // 请求的url,必须
  280. },
  281. function (err, data) {
  282. if (err) {
  283. // 处理请求失败
  284. console.log(err);
  285. } else {
  286. // 处理请求成功
  287. console.log(data.Response);
  288. }
  289. }
  290. );
  291. }
  292. function postPosterProductionJob() {
  293. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  294. const key = `pic_jobs`; //
  295. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  296. const url = `https://${host}/${key}`;
  297. const body = COS.util.json2xml({
  298. Request: {
  299. // 创建任务的 Tag:PicProcess;是否必传:是
  300. Tag: 'PosterProduction',
  301. // 待操作的媒体信息;是否必传:是
  302. Input: {
  303. // 媒体文件名;是否必传:是
  304. Object: '1.jpeg ',
  305. },
  306. // 操作规则;是否必传:是
  307. Operation: {
  308. // 指定该任务的参数;是否必传:否
  309. PosterProduction: {
  310. // ;是否必传:是
  311. TemplateId: 'xxx',
  312. Info: {
  313. main: 'https://examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/1.jpeg',
  314. text_main: 'demo',
  315. },
  316. },
  317. // 结果输出地址;是否必传:是
  318. Output: {
  319. // 存储桶的地域;是否必传:是
  320. Region: config.Region,
  321. // 存储结果的存储桶;是否必传:是
  322. Bucket: config.Bucket,
  323. // 结果文件的名字;是否必传:是
  324. Object: 'test.jpg',
  325. },
  326. // 透传用户信息, 可打印的 ASCII 码, 长度不超过1024;是否必传:否
  327. UserData: '',
  328. // 任务优先级,级别限制:0 、1 、2 。级别越大任务优先级越高,默认为0;是否必传:否
  329. JobLevel: '0',
  330. },
  331. // 任务所在的队列 ID;是否必传:否
  332. QueueId: '',
  333. // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式;是否必传:否
  334. CallBackFormat: '',
  335. // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型;是否必传:否
  336. CallBackType: 'Url',
  337. // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调;是否必传:否
  338. CallBack: '',
  339. },
  340. });
  341. cos.request(
  342. {
  343. Method: 'POST', // 固定值,必须
  344. Key: key, // 必须
  345. Url: url, // 请求的url,必须
  346. Body: body, // 请求体参数,必须
  347. ContentType: 'application/xml', // 固定值,必须
  348. },
  349. function (err, data) {
  350. if (err) {
  351. // 处理请求失败
  352. console.log(err);
  353. } else {
  354. // 处理请求成功
  355. console.log(data.Response);
  356. }
  357. }
  358. );
  359. }
  360. function describePosterProductionTemplate() {
  361. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  362. const TemplateId = 'xxx';
  363. const key = `posterproduction/template/${TemplateId}`; // TemplateId:{TemplateId};
  364. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  365. const url = `https://${host}/${key}`;
  366. cos.request(
  367. {
  368. Method: 'GET', // 固定值,必须
  369. Key: key, // 必须
  370. Url: url, // 请求的url,必须
  371. },
  372. function (err, data) {
  373. if (err) {
  374. // 处理请求失败
  375. console.log(err);
  376. } else {
  377. // 处理请求成功
  378. console.log(data.Response);
  379. }
  380. }
  381. );
  382. }
  383. function describePosterProductionTemplateList() {
  384. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  385. const key = `posterproduction/template`; //
  386. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  387. const url = `https://${host}/${key}`;
  388. cos.request(
  389. {
  390. Method: 'GET', // 固定值,必须
  391. Key: key, // 必须
  392. Url: url, // 请求的url,必须
  393. Query: {
  394. // 模板分类ID,支持传入多个,以,符号分割字符串;是否必传:否
  395. categoryIds: '',
  396. // Official(系统预设模板),Custom(自定义模板),All(所有模板),默认值: Custom;是否必传:否
  397. type: 'Custom',
  398. },
  399. },
  400. function (err, data) {
  401. if (err) {
  402. // 处理请求失败
  403. console.log(err);
  404. } else {
  405. // 处理请求成功
  406. console.log(data.Response);
  407. }
  408. }
  409. );
  410. }
  411. function deletePosterProductionTemplate() {
  412. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  413. const TemplateId = 'xxx';
  414. const key = `posterproduction/template/${TemplateId}`; // TemplateId:{TemplateId};
  415. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  416. const url = `https://${host}/${key}`;
  417. cos.request(
  418. {
  419. Method: 'DELETE', // 固定值,必须
  420. Key: key, // 必须
  421. Url: url, // 请求的url,必须
  422. },
  423. function (err, data) {
  424. if (err) {
  425. // 处理请求失败
  426. console.log(err);
  427. } else {
  428. // 处理请求成功
  429. console.log(data.Response);
  430. }
  431. }
  432. );
  433. }
  434. function uploadPosterProductionTemplate() {
  435. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  436. const key = `posterproduction/template`; //
  437. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  438. const url = `https://${host}/${key}`;
  439. const body = COS.util.json2xml({
  440. Request: {
  441. // 输入参数;是否必传:否
  442. Input: {
  443. // COS 桶中 PSD 文件,大小限制100M;是否必传:是
  444. Object: 'test.psd',
  445. },
  446. // 模板名称;是否必传:是
  447. Name: 'test',
  448. // 模板分类 ID,支持传入多个,以 , 符号分割字符串;是否必传:否
  449. CategoryIds: '',
  450. },
  451. });
  452. cos.request(
  453. {
  454. Method: 'POST', // 固定值,必须
  455. Key: key, // 必须
  456. Url: url, // 请求的url,必须
  457. Body: body, // 请求体参数,必须
  458. ContentType: 'application/xml', // 固定值,必须
  459. },
  460. function (err, data) {
  461. if (err) {
  462. // 处理请求失败
  463. console.log(err);
  464. } else {
  465. // 处理请求成功
  466. console.log(data.Response);
  467. }
  468. }
  469. );
  470. }
  471. function openImageGuetzli() {
  472. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  473. const key = ``; //
  474. const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
  475. const url = `https://${host}/${key}`;
  476. cos.request(
  477. {
  478. Method: 'PUT', // 固定值,必须
  479. Key: key, // 必须
  480. Url: url, // 请求的url,必须
  481. Action: 'guetzli', // 固定值
  482. },
  483. function (err, data) {
  484. if (err) {
  485. // 处理请求失败
  486. console.log(err);
  487. } else {
  488. // 处理请求成功
  489. console.log(data.Response);
  490. }
  491. }
  492. );
  493. }
  494. function describeImageGuetzli() {
  495. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  496. const key = ``; //
  497. const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
  498. const url = `https://${host}/${key}`;
  499. cos.request(
  500. {
  501. Method: 'GET', // 固定值,必须
  502. Key: key, // 必须
  503. Url: url, // 请求的url,必须
  504. Action: 'guetzli', // 固定值
  505. },
  506. function (err, data) {
  507. if (err) {
  508. // 处理请求失败
  509. console.log(err);
  510. } else {
  511. // 处理请求成功
  512. console.log(data.Response);
  513. }
  514. }
  515. );
  516. }
  517. function closeImageGuetzli() {
  518. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  519. const key = ``; //
  520. const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
  521. const url = `https://${host}/${key}`;
  522. cos.request(
  523. {
  524. Method: 'DELETE', // 固定值,必须
  525. Key: key, // 必须
  526. Url: url, // 请求的url,必须
  527. Action: 'guetzli', // 固定值
  528. },
  529. function (err, data) {
  530. if (err) {
  531. // 处理请求失败
  532. console.log(err);
  533. } else {
  534. // 处理请求成功
  535. console.log(data.Response);
  536. }
  537. }
  538. );
  539. }
  540. function createImageProcessJob() {
  541. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  542. const key = `jobs`; //
  543. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  544. const url = `https://${host}/${key}`;
  545. const body = COS.util.json2xml({
  546. Request: {
  547. // 创建任务的 Tag:PicProcess;是否必传:是
  548. Tag: 'PicProcess',
  549. // 待操作的文件信息;是否必传:是
  550. Input: {
  551. // 文件路径;是否必传:是
  552. Object: '1.jpeg',
  553. },
  554. // 操作规则;是否必传:是
  555. Operation: {
  556. // 图片处理模板 ID;是否必传:否
  557. TemplateId: 'xxx',
  558. // 结果输出配置;是否必传:是
  559. Output: {
  560. // 存储桶的地域;是否必传:是
  561. Region: config.Region,
  562. // 存储结果的存储桶;是否必传:是
  563. Bucket: config.Bucket,
  564. // 结果文件的名字;是否必传:是
  565. Object: 'output/1.jpeg',
  566. },
  567. // 透传用户信息,可打印的 ASCII 码,长度不超过1024;是否必传:否
  568. UserData: '',
  569. // 任务优先级,级别限制:0 、1 、2 。级别越大任务优先级越高,默认为0;是否必传:否
  570. JobLevel: '0',
  571. },
  572. // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式;是否必传:否
  573. CallBackFormat: '',
  574. // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型;是否必传:否
  575. CallBackType: 'Url',
  576. // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调;是否必传:否
  577. CallBack: '',
  578. },
  579. });
  580. cos.request(
  581. {
  582. Method: 'POST', // 固定值,必须
  583. Key: key, // 必须
  584. Url: url, // 请求的url,必须
  585. Body: body, // 请求体参数,必须
  586. ContentType: 'application/xml', // 固定值,必须
  587. },
  588. function (err, data) {
  589. if (err) {
  590. // 处理请求失败
  591. console.log(err);
  592. } else {
  593. // 处理请求成功
  594. console.log(data.Response);
  595. }
  596. }
  597. );
  598. }
  599. function createImageProcessTemplate() {
  600. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  601. const key = `template`; //
  602. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  603. const url = `https://${host}/${key}`;
  604. const body = COS.util.json2xml({
  605. Request: {
  606. // 模板类型:PicProcess;是否必传:是
  607. Tag: 'PicProcess',
  608. // 模板名称,仅支持中文、英文、数字、_、-和*,长度不超过 64;是否必传:是
  609. Name: 'test',
  610. // 图片处理参数;是否必传:是
  611. PicProcess: {
  612. // 是否返回原图信息,取值 true/false;是否必传:否
  613. IsPicInfo: '',
  614. // 图片处理规则基础图片处理参见 基础图片处理文档图片压缩参见 图片压缩 文档盲水印参见 盲水印 文档;是否必传:是
  615. ProcessRule: 'imageMogr2/rotate/9',
  616. },
  617. },
  618. });
  619. cos.request(
  620. {
  621. Method: 'POST', // 固定值,必须
  622. Key: key, // 必须
  623. Url: url, // 请求的url,必须
  624. Body: body, // 请求体参数,必须
  625. ContentType: 'application/xml', // 固定值,必须
  626. },
  627. function (err, data) {
  628. if (err) {
  629. // 处理请求失败
  630. console.log(err);
  631. } else {
  632. // 处理请求成功
  633. console.log(data.Response);
  634. }
  635. }
  636. );
  637. }
  638. function updateImageProcessTemplate() {
  639. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  640. const TemplateId = 'xxx';
  641. const key = `template/${TemplateId}`; // TemplateId:{TemplateId};
  642. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  643. const url = `https://${host}/${key}`;
  644. const body = COS.util.json2xml({
  645. Request: {
  646. // 模板类型:PicProcess;是否必传:是
  647. Tag: 'PicProcess',
  648. // 模板名称,仅支持中文、英文、数字、_、-和*,长度不超过 64;是否必传:是
  649. Name: 'test',
  650. // 图片处理参数;是否必传:是
  651. PicProcess: {
  652. // 是否返回原图信息,取值 true/false;是否必传:否
  653. IsPicInfo: '',
  654. // 图片处理规则基础图片处理参见 基础图片处理文档图片压缩参见 图片压缩 文档盲水印参见 盲水印 文档;是否必传:是
  655. ProcessRule: 'imageMogr2/rotate/99',
  656. },
  657. },
  658. });
  659. cos.request(
  660. {
  661. Method: 'PUT', // 固定值,必须
  662. Key: key, // 必须
  663. Url: url, // 请求的url,必须
  664. Body: body, // 请求体参数,必须
  665. ContentType: 'application/xml', // 固定值,必须
  666. },
  667. function (err, data) {
  668. if (err) {
  669. // 处理请求失败
  670. console.log(err);
  671. } else {
  672. // 处理请求成功
  673. console.log(data.Response);
  674. }
  675. }
  676. );
  677. }
  678. function addImageStyle() {
  679. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  680. const key = ``; //
  681. const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
  682. const url = `https://${host}/${key}`;
  683. const body = COS.util.json2xml({
  684. AddStyle: {
  685. // 样式名称;是否必传:是
  686. StyleName: 'test',
  687. // 样式详情;是否必传:是
  688. StyleBody: 'imageMogr2/thumbnail/!50px',
  689. },
  690. });
  691. cos.request(
  692. {
  693. Method: 'PUT', // 固定值,必须
  694. Key: key, // 必须
  695. Url: url, // 请求的url,必须
  696. Action: 'style', // 固定值
  697. Body: body,
  698. ContentType: 'application/xml', // 固定值,必须
  699. },
  700. function (err, data) {
  701. if (err) {
  702. // 处理请求失败
  703. console.log(err);
  704. } else {
  705. // 处理请求成功
  706. console.log(data.Response);
  707. }
  708. }
  709. );
  710. }
  711. function describeImageStyles() {
  712. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  713. const key = ``; //
  714. const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
  715. const url = `https://${host}/${key}`;
  716. cos.request(
  717. {
  718. Method: 'GET', // 固定值,必须
  719. Key: key, // 必须
  720. Url: url, // 请求的url,必须
  721. Action: 'style', // 固定值
  722. Query: {
  723. GetStyle: {
  724. // 查询的图片样式名称。;是否必传:否
  725. StyleName: 'test',
  726. },
  727. },
  728. },
  729. function (err, data) {
  730. if (err) {
  731. // 处理请求失败
  732. console.log(err);
  733. } else {
  734. // 处理请求成功
  735. console.log(data.Response);
  736. }
  737. }
  738. );
  739. }
  740. function deleteImageStyles() {
  741. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  742. const key = ``; //
  743. const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
  744. const url = `https://${host}/${key}`;
  745. const body = COS.util.json2xml({
  746. DeleteStyle: {
  747. // 样式名称;是否必传:是
  748. StyleName: 'test',
  749. },
  750. });
  751. cos.request(
  752. {
  753. Method: 'DELETE', // 固定值,必须
  754. Key: key, // 必须
  755. Url: url, // 请求的url,必须
  756. Action: 'style', // 固定值
  757. Body: body,
  758. ContentType: 'application/xml', // 固定值,必须
  759. },
  760. function (err, data) {
  761. if (err) {
  762. // 处理请求失败
  763. console.log(err);
  764. } else {
  765. // 处理请求成功
  766. console.log(data.Response);
  767. }
  768. }
  769. );
  770. }
  771. function imageInspectSync() {
  772. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  773. const ObjectKey = 'test.jpg';
  774. const key = `${ObjectKey}`; // ObjectKey:{ObjectKey};
  775. const host = `${config.Bucket}.cos.${config.Region}.myqcloud.com`;
  776. const url = `https://${host}/${key}`;
  777. cos.request(
  778. {
  779. Method: 'GET', // 固定值,必须
  780. Key: key, // 必须
  781. Url: url, // 请求的url,必须
  782. Query: {
  783. // ;是否必传:是
  784. 'ci-process': 'ImageInspect',
  785. },
  786. },
  787. function (err, data) {
  788. if (err) {
  789. // 处理请求失败
  790. console.log(err);
  791. } else {
  792. // 处理请求成功
  793. console.log(data.Response);
  794. }
  795. }
  796. );
  797. }
  798. function createImageInspectJob() {
  799. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  800. const key = `jobs`; //
  801. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  802. const url = `https://${host}/${key}`;
  803. const body = COS.util.json2xml({
  804. Request: {
  805. // 创建任务的 Tag:ImageInspect;是否必传:是
  806. Tag: 'ImageInspect',
  807. // 待操作的文件信息;是否必传:是
  808. Input: {
  809. // 文件路径;是否必传:是
  810. Object: 'test.jpg',
  811. },
  812. // 操作规则;是否必传:否
  813. Operation: {
  814. // 透传用户信息,可打印的 ASCII 码,长度不超过1024;是否必传:否
  815. UserData: '',
  816. // 任务优先级,级别限制:0 、1 、2 。级别越大任务优先级越高,默认为0;是否必传:否
  817. JobLevel: '0',
  818. // 该任务的参数;是否必传:否
  819. ImageInspect: {
  820. // 是否开启识别到图片异常后自动对图片进行如移动到其他目录、设置为私有权限、删除等动作。取值:true/false,默认为false;是否必传:否
  821. AutoProcess: '',
  822. // 指定检测到异常图片后的处理动作BackupObject:将图片移动 abnormal_images_backup下,该目录由后台自动创建SwitchObjectToPrivate:将图片权限设置为私有DeleteObject:删除图片默认值:BackupObject当 AutoProcess 为 true 时,该参数生效;是否必传:否
  823. ProcessType: '',
  824. },
  825. },
  826. // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式;是否必传:否
  827. CallBackFormat: '',
  828. // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型;是否必传:否
  829. CallBackType: 'Url',
  830. // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调;是否必传:否
  831. CallBack: '',
  832. },
  833. });
  834. cos.request(
  835. {
  836. Method: 'POST', // 固定值,必须
  837. Key: key, // 必须
  838. Url: url, // 请求的url,必须
  839. Body: body, // 请求体参数,必须
  840. ContentType: 'application/xml', // 固定值,必须
  841. },
  842. function (err, data) {
  843. if (err) {
  844. // 处理请求失败
  845. console.log(err);
  846. } else {
  847. // 处理请求成功
  848. console.log(data.Response);
  849. }
  850. }
  851. );
  852. }
  853. function openImageProcessService() {
  854. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  855. const key = `picbucket`; //
  856. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  857. const url = `https://${host}/${key}`;
  858. cos.request(
  859. {
  860. Method: 'POST', // 固定值,必须
  861. Key: key, // 必须
  862. Url: url, // 请求的url,必须
  863. },
  864. function (err, data) {
  865. if (err) {
  866. // 处理请求失败
  867. console.log(err);
  868. } else {
  869. // 处理请求成功
  870. console.log(data.Response);
  871. }
  872. }
  873. );
  874. }
  875. function describeImageProcessService() {
  876. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  877. const key = `picbucket`; //
  878. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  879. const url = `https://${host}/${key}`;
  880. cos.request(
  881. {
  882. Method: 'GET', // 固定值,必须
  883. Key: key, // 必须
  884. Url: url, // 请求的url,必须
  885. Query: {
  886. // 地域信息,以“,”分隔字符串,支持 All、ap-shanghai、ap-beijing;是否必传:否
  887. regions: '',
  888. // 存储桶名称,以“,”分隔,支持多个存储桶,精确搜索;是否必传:否
  889. bucketNames: '',
  890. // 存储桶名称前缀,前缀搜索;是否必传:否
  891. bucketName: 'test',
  892. // 第几页;是否必传:否
  893. pageNumber: '',
  894. // 每页个数;是否必传:否
  895. pageSize: '',
  896. },
  897. },
  898. function (err, data) {
  899. if (err) {
  900. // 处理请求失败
  901. console.log(err);
  902. } else {
  903. // 处理请求成功
  904. console.log(data.Response);
  905. }
  906. }
  907. );
  908. }
  909. function closeImageProcessService() {
  910. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  911. const key = `picbucket`; //
  912. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  913. const url = `https://${host}/${key}`;
  914. cos.request(
  915. {
  916. Method: 'DELETE', // 固定值,必须
  917. Key: key, // 必须
  918. Url: url, // 请求的url,必须
  919. },
  920. function (err, data) {
  921. if (err) {
  922. // 处理请求失败
  923. console.log(err);
  924. } else {
  925. // 处理请求成功
  926. console.log(data.Response);
  927. }
  928. }
  929. );
  930. }
  931. function describeImageProcessQueue() {
  932. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  933. const key = `picqueue`; //
  934. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  935. const url = `https://${host}/${key}`;
  936. cos.request(
  937. {
  938. Method: 'GET', // 固定值,必须
  939. Key: key, // 必须
  940. Url: url, // 请求的url,必须
  941. Query: {
  942. // 队列 ID,以“,”符号分割字符串;是否必传:否
  943. queueIds: '',
  944. // Active 表示队列内的作业会被调度执行Paused 表示队列暂停,作业不再会被调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响;是否必传:否
  945. state: 'Active',
  946. // 第几页,默认值1;是否必传:否
  947. pageNumber: '',
  948. // 每页个数,默认值10;是否必传:否
  949. pageSize: '',
  950. },
  951. },
  952. function (err, data) {
  953. if (err) {
  954. // 处理请求失败
  955. console.log(err);
  956. } else {
  957. // 处理请求成功
  958. console.log(data.Response);
  959. }
  960. }
  961. );
  962. }
  963. function updateImageProcessQueue() {
  964. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  965. const queueId = 'xxx';
  966. const key = `picqueue/${queueId}`; // queueId:{queueId};
  967. const host = `${config.Bucket}.ci.${config.Region}.myqcloud.com`;
  968. const url = `https://${host}/${key}`;
  969. const body = COS.util.json2xml({
  970. Request: {
  971. // 队列名称,仅支持中文、英文、数字、_、-和*,长度不超过 128;是否必传:是
  972. Name: 'xxx',
  973. // Active 表示队列内的作业会被调度执行Paused 表示队列暂停,作业不再会被调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响;是否必传:是
  974. State: 'Active',
  975. // 回调配置;是否必传:是
  976. NotifyConfig: {
  977. // 回调开关OffOn;是否必传:否
  978. State: 'Off',
  979. // 回调事件TaskFinish:任务完成WorkflowFinish:工作流完成;是否必传:否
  980. // Event: "",
  981. // 回调格式XMLJSON;是否必传:否
  982. // ResultFormat: "",
  983. // 回调类型UrlTDMQ;是否必传:否
  984. // Type: "",
  985. // 回调地址,不能为内网地址。;是否必传:否
  986. // Url: "",
  987. // TDMQ 使用模式Topic:主题订阅Queue: 队列服务;是否必传:否
  988. // MqMode: "",
  989. // TDMQ 所属园区,目前支持园区 sh(上海)、bj(北京)、gz(广州)、cd(成都)、hk(中国香港);是否必传:否
  990. // MqRegion: "",
  991. // TDMQ 主题名称;是否必传:否
  992. // MqName: "",
  993. },
  994. },
  995. });
  996. cos.request(
  997. {
  998. Method: 'PUT', // 固定值,必须
  999. Key: key, // 必须
  1000. Url: url, // 请求的url,必须
  1001. Body: body, // 请求体参数,必须
  1002. ContentType: 'application/xml', // 固定值,必须
  1003. },
  1004. function (err, data) {
  1005. if (err) {
  1006. // 处理请求失败
  1007. console.log(err);
  1008. } else {
  1009. // 处理请求成功
  1010. console.log(data.Response);
  1011. }
  1012. }
  1013. );
  1014. }
  1015. function openImageSlim() {
  1016. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  1017. const key = ``; //
  1018. const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
  1019. const url = `https://${host}/${key}`;
  1020. const body = COS.util.json2xml({
  1021. // 极智压缩配置信息
  1022. ImageSlim: {
  1023. // 极智压缩的使用模式,包含两种:API:开通极智压缩的 API 使用方式,开通后可在图片下载时通过极智压缩参数对图片进行压缩;Auto:开通极智压缩的自动使用方式,开通后无需携带任何参数,存储桶内指定格式的图片将在访问时自动进行极智压缩。注意:支持同时开通两种模式,多个值通过逗号分隔。
  1024. SlimMode: 'Auto,API',
  1025. // 当SlimMode的值包含Auto时生效,用于指定需要自动进行压缩的图片格式。
  1026. Suffixs: {
  1027. // 需要自动进行压缩的图片格式,可选值:jpg、png。
  1028. Suffix: 'jpg',
  1029. },
  1030. },
  1031. });
  1032. cos.request(
  1033. {
  1034. Method: 'PUT', // 固定值,必须
  1035. Key: key, // 必须
  1036. Url: url, // 请求的url,必须
  1037. Action: 'image-slim', // 固定值
  1038. Body: body, // 请求体参数,必须
  1039. ContentType: 'application/xml', // 固定值,必须
  1040. },
  1041. function (err, data) {
  1042. if (err) {
  1043. // 处理请求失败
  1044. console.log(err);
  1045. } else {
  1046. // 处理请求成功
  1047. console.log(data.Response);
  1048. }
  1049. }
  1050. );
  1051. }
  1052. function describeImageSlim() {
  1053. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  1054. const key = ``; //
  1055. const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
  1056. const url = `https://${host}/${key}`;
  1057. cos.request(
  1058. {
  1059. Method: 'GET', // 固定值,必须
  1060. Key: key, // 必须
  1061. Url: url, // 请求的url,必须
  1062. Action: 'image-slim', // 固定值
  1063. },
  1064. function (err, data) {
  1065. if (err) {
  1066. // 处理请求失败
  1067. console.log(err);
  1068. } else {
  1069. // 处理请求成功
  1070. console.log(data.Response);
  1071. }
  1072. }
  1073. );
  1074. }
  1075. function closeImageSlim() {
  1076. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  1077. const key = ``; //
  1078. const host = `${config.Bucket}.pic.${config.Region}.myqcloud.com`;
  1079. const url = `https://${host}/${key}`;
  1080. cos.request(
  1081. {
  1082. Method: 'DELETE', // 固定值,必须
  1083. Key: key, // 必须
  1084. Url: url, // 请求的url,必须
  1085. Action: 'image-slim', // 固定值
  1086. },
  1087. function (err, data) {
  1088. if (err) {
  1089. // 处理请求失败
  1090. console.log(err);
  1091. } else {
  1092. // 处理请求成功
  1093. console.log(data.Response);
  1094. }
  1095. }
  1096. );
  1097. }
  1098. function imageSlim() {
  1099. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  1100. const ObjectKey = 'test.jpeg';
  1101. const key = `${ObjectKey}`; // ObjectKey:{ObjectKey};
  1102. const host = `${config.Bucket}.cos.${config.Region}.myqcloud.com`;
  1103. const url = `https://${host}/${key}`;
  1104. cos.request(
  1105. {
  1106. Method: 'GET', // 固定值,必须
  1107. Key: key, // 必须
  1108. Url: url, // 请求的url,必须
  1109. Action: 'imageSlim', // 固定值
  1110. },
  1111. function (err, data) {
  1112. if (err) {
  1113. // 处理请求失败
  1114. console.log(err);
  1115. } else {
  1116. // 处理请求成功
  1117. console.log(data.Response);
  1118. }
  1119. }
  1120. );
  1121. }
  1122. function getOriginImage() {
  1123. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/
  1124. const ObjectKey = 'test.jpg';
  1125. const key = `${ObjectKey}`; // ObjectKey:{ObjectKey};
  1126. const host = `${config.Bucket}.cos.${config.Region}.myqcloud.com`;
  1127. const url = `https://${host}/${key}`;
  1128. cos.request(
  1129. {
  1130. Method: 'GET', // 固定值,必须
  1131. Key: key, // 必须
  1132. Url: url, // 请求的url,必须
  1133. Query: {
  1134. // 万象通用参数,需要获取原图的时,该参数固定为:originImage;是否必传:是
  1135. 'ci-process': 'originImage',
  1136. },
  1137. },
  1138. function (err, data) {
  1139. if (err) {
  1140. // 处理请求失败
  1141. console.log(err);
  1142. } else {
  1143. // 处理请求成功
  1144. console.log(data.Response);
  1145. }
  1146. }
  1147. );
  1148. }
  1149. function uploadImgAnimate() {
  1150. wx.chooseMessageFile({
  1151. count: 2,
  1152. type: 'all',
  1153. success: function (res) {
  1154. var file = res.tempFiles[0];
  1155. wxfs.readFile({
  1156. filePath: file.path,
  1157. success: function (res) {
  1158. cos.putObject(
  1159. {
  1160. Bucket: config.Bucket, // Bucket 格式:test-1250000000
  1161. Region: config.Region,
  1162. Key: file.name,
  1163. Body: res.data,
  1164. Headers: {
  1165. 'Pic-Operations':
  1166. '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "imageMogr2/animate/duration/10/images/<imageurl1>"}]}',
  1167. },
  1168. },
  1169. requestCallback
  1170. );
  1171. },
  1172. fail: (err) => console.error(err),
  1173. });
  1174. },
  1175. fail: (err) => console.error(err),
  1176. });
  1177. }
  1178. function requestImgAnimate() {
  1179. // 对云上数据进行图片处理
  1180. cos.request(
  1181. {
  1182. Bucket: config.Bucket,
  1183. Region: config.Region,
  1184. Key: '1.jpeg',
  1185. Method: 'POST',
  1186. Action: 'image_process',
  1187. Headers: {
  1188. 'Pic-Operations':
  1189. '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "imageMogr2/animate/duration/10/images/<imageurl1>"}]}',
  1190. },
  1191. },
  1192. requestCallback
  1193. );
  1194. }
  1195. function getImgAnimate() {
  1196. cos.getObject(
  1197. {
  1198. Bucket: config.Bucket,
  1199. Region: config.Region,
  1200. Key: '1.png',
  1201. QueryString: `imageMogr2/animate/duration/10/images/<imageurl1>`,
  1202. },
  1203. requestCallback
  1204. );
  1205. }
  1206. function uploadImgWatermark() {
  1207. wx.chooseMessageFile({
  1208. count: 2,
  1209. type: 'all',
  1210. success: function (res) {
  1211. var file = res.tempFiles[0];
  1212. wxfs.readFile({
  1213. filePath: file.path,
  1214. success: function (res) {
  1215. cos.putObject(
  1216. {
  1217. Bucket: config.Bucket, // Bucket 格式:test-1250000000
  1218. Region: config.Region,
  1219. Key: file.name,
  1220. Body: res.data,
  1221. Headers: {
  1222. 'Pic-Operations':
  1223. '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "watermark/1/image/<encodedURL>/gravity/SouthEast/dx/10/dy/10/blogo/1"}]}',
  1224. },
  1225. },
  1226. requestCallback
  1227. );
  1228. },
  1229. fail: (err) => console.error(err),
  1230. });
  1231. },
  1232. fail: (err) => console.error(err),
  1233. });
  1234. }
  1235. function requestImgWatermark() {
  1236. // 对云上数据进行图片处理
  1237. cos.request(
  1238. {
  1239. Bucket: config.Bucket,
  1240. Region: config.Region,
  1241. Key: '1.jpeg',
  1242. Method: 'POST',
  1243. Action: 'image_process',
  1244. Headers: {
  1245. 'Pic-Operations':
  1246. '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "watermark/1/image/<encodedURL>/gravity/SouthEast/dx/10/dy/10/blogo/1"}]}',
  1247. },
  1248. },
  1249. requestCallback
  1250. );
  1251. }
  1252. function getImgWatermark() {
  1253. cos.getObject(
  1254. {
  1255. Bucket: config.Bucket,
  1256. Region: config.Region,
  1257. Key: 'test.jpg',
  1258. QueryString: `watermark/1/image/<encodedURL>/gravity/SouthEast/dx/10/dy/10/blogo/1`,
  1259. },
  1260. requestCallback
  1261. );
  1262. }
  1263. function uploadImgWatermarkText() {
  1264. wx.chooseMessageFile({
  1265. count: 2,
  1266. type: 'all',
  1267. success: function (res) {
  1268. var file = res.tempFiles[0];
  1269. wxfs.readFile({
  1270. filePath: file.path,
  1271. success: function (res) {
  1272. cos.putObject(
  1273. {
  1274. Bucket: config.Bucket, // Bucket 格式:test-1250000000
  1275. Region: config.Region,
  1276. Key: file.name,
  1277. Body: res.data,
  1278. Headers: {
  1279. 'Pic-Operations':
  1280. '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "watermark/2/text/5paH5a2X5rC05Y2w5rWL6K-V/fontsize/16/dissolve/100/gravity/SouthEast/dx/10/dy/10/batch/1/degree/45/shadow/50"}]}',
  1281. },
  1282. },
  1283. requestCallback
  1284. );
  1285. },
  1286. fail: (err) => console.error(err),
  1287. });
  1288. },
  1289. fail: (err) => console.error(err),
  1290. });
  1291. }
  1292. function requestImgWatermarkText() {
  1293. // 对云上数据进行图片处理
  1294. cos.request(
  1295. {
  1296. Bucket: config.Bucket,
  1297. Region: config.Region,
  1298. Key: '1.jpeg',
  1299. Method: 'POST',
  1300. Action: 'image_process',
  1301. Headers: {
  1302. 'Pic-Operations':
  1303. '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject", "rule": "watermark/2/text/5paH5a2X5rC05Y2w5rWL6K-V/fontsize/16/dissolve/100/gravity/SouthEast/dx/10/dy/10/batch/1/degree/45/shadow/50"}]}',
  1304. },
  1305. },
  1306. requestCallback
  1307. );
  1308. }
  1309. function getImgWatermarkText() {
  1310. cos.getObject(
  1311. {
  1312. Bucket: config.Bucket,
  1313. Region: config.Region,
  1314. Key: 'test.jpg',
  1315. QueryString: `watermark/2/text/5paH5a2X5rC05Y2w5rWL6K-V/fontsize/16/dissolve/100/gravity/SouthEast/dx/10/dy/10/batch/1/degree/45/shadow/50`,
  1316. },
  1317. requestCallback
  1318. );
  1319. }
  1320. function uploadImgCompress() {
  1321. wx.chooseMessageFile({
  1322. count: 2,
  1323. type: 'all',
  1324. success: function (res) {
  1325. var file = res.tempFiles[0];
  1326. wxfs.readFile({
  1327. filePath: file.path,
  1328. success: function (res) {
  1329. cos.putObject(
  1330. {
  1331. Bucket: config.Bucket, // Bucket 格式:test-1250000000
  1332. Region: config.Region,
  1333. Key: file.name,
  1334. Body: res.data,
  1335. Headers: {
  1336. // 通过 imageMogr2 接口进行 webp 压缩,可以根据需要压缩的类型填入不同的压缩格式:webp/heif/tpg/avif/svgc
  1337. 'Pic-Operations':
  1338. '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject.jpg", "rule": "imageMogr2/format/webp"}]}',
  1339. },
  1340. },
  1341. requestCallback
  1342. );
  1343. },
  1344. fail: (err) => console.error(err),
  1345. });
  1346. },
  1347. fail: (err) => console.error(err),
  1348. });
  1349. }
  1350. function requestImgCompress() {
  1351. // 对云上数据进行图片处理
  1352. cos.request(
  1353. {
  1354. Bucket: config.Bucket,
  1355. Region: config.Region,
  1356. Key: '1.jpeg',
  1357. Method: 'POST',
  1358. Action: 'image_process',
  1359. Headers: {
  1360. // 通过 imageMogr2 接口进行 webp 压缩,可以根据需要压缩的类型填入不同的压缩格式:webp/heif/tpg/avif/svgc
  1361. 'Pic-Operations':
  1362. '{"is_pic_info": 1, "rules": [{"fileid": "exampleobject.jpeg", "rule": "imageMogr2/format/webp"}]}',
  1363. },
  1364. },
  1365. requestCallback
  1366. );
  1367. }
  1368. function getImgCompress() {
  1369. cos.getObject(
  1370. {
  1371. Bucket: config.Bucket,
  1372. Region: config.Region,
  1373. Key: 'test.jpg',
  1374. QueryString: `imageMogr2/format/webp`, // 通过 imageMogr2 接口进行 webp 压缩,可以根据需要压缩的类型填入不同的压缩格式:webp/heif/tpg/avif/svgc
  1375. },
  1376. requestCallback
  1377. );
  1378. }
  1379. module.exports = picProcessDao;