@cutting/cloudinary-blurhash 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export declare function generateBlurhashFile(fileName: string): Promise<void>;
2
+ //# sourceMappingURL=generateBlurhashFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateBlurhashFile.d.ts","sourceRoot":"","sources":["../../src/generateBlurhashFile.ts"],"names":[],"mappings":"AAsCA,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA2C1E"}
@@ -0,0 +1,2 @@
1
+ export declare const program: import("commander").Command;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,6BAAsC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{createCommand as e}from"commander";import{v2 as o}from"cloudinary";import r from"fs";import{config as s}from"dotenv";import{getPixels as t}from"@unpic/pixels";import{encode as i}from"blurhash";import n from"chalk";import c from"log-update";import l from"path";const{promises:{writeFile:a}}=r;s(),o.config({secure:!0}),console.log(o.config());const h=e("generate-blur-hash");h.description("generate low quality placeholder (LQIP) using blurhash").option("-f, --file <file>","the name of the the json file","./blurhash_image_map.json").parse(process.argv).action((async function({file:e}){try{!async function(e){const r=process.hrtime(),s=l.join(process.cwd(),e),h=[],g=(await o.search.expression("format=(NOT ico)").max_results(1e3).execute()).resources.map((({secure_url:e,width:o,height:r})=>({secure_url:e,width:o,height:r})));console.clear(),console.log(`About to process ${n.green(g.length)} images`);for(const e of g){const o=await t(e.secure_url),s=Uint8ClampedArray.from(o.data),l=i(s,o.width,o.height,4,4),a=e.secure_url.split("/");h.push({id:a.slice(-1)[0],url:e.secure_url,blurhash:l,width:e.width,height:e.height});const x=((w=process.hrtime(r))[0]+w[1]/1e9).toFixed(3);m=n.green.bold(`${d=h.length,b=g.length,(100*d/b).toFixed(2)}%`),p=n.green.bold(""+(g.length-h.length)),u=n.green.bold(`${h.length}`),f=n.green.bold(x),c(`\n${m} Processed.\n\n${p} images remaining to process\n\n${u} images processed ✅\n\nProcess started ${f}s ago`)}var m,p,u,f,d,b,w;console.log(n.blue(`writing results to ${s}`)),a(s,JSON.stringify(h))}(e)}catch(e){console.error(e),process.exit(1)}})).parse(process.argv);export{h as program};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/generateBlurhashFile.ts","../../src/index.ts"],"sourcesContent":["import { v2 } from 'cloudinary';\nimport fs from 'fs';\nimport { config } from 'dotenv';\nimport type { BlurHashImage, SearchResults } from './types';\nimport { getPixels } from '@unpic/pixels';\nimport { encode } from 'blurhash';\nimport chalk from 'chalk';\nimport logUpdate from 'log-update';\nimport path from 'path';\n\nconst {\n promises: { writeFile },\n} = fs;\n\nconfig();\n\nv2.config({ secure: true });\n\n// v2.config({\n// cloud_name: process.env.CLOUDINARY_CLOUD_NAME,\n// api_key: process.env.CLOUDINARY_API_KEY,\n// api_secret: process.env.CLOUDINARY_API_SECRET,\n// });\n\nconsole.log(v2.config());\n\nconst percentage = (partialValue: number, totalValue: number) => ((100 * partialValue) / totalValue).toFixed(2);\n\nconst parseHrtimeToSeconds = (hrtime: [number, number]) => {\n const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3);\n return seconds;\n};\n\nconst updateLogs = (a: unknown, b: unknown, c: unknown, d: unknown) =>\n logUpdate(\n `\\n${a} Processed.\\n\\n${b} images remaining to process\\n\\n${c} images processed ✅\\n\\nProcess started ${d}s ago`,\n );\n\nexport async function generateBlurhashFile(fileName: string): Promise<void> {\n const startTime = process.hrtime();\n const outFile = path.join(process.cwd(), fileName);\n\n const blurhashImages: BlurHashImage[] = [];\n\n const results: SearchResults = await v2.search.expression('format=(NOT ico)').max_results(1000).execute();\n\n const images = results.resources.map(({ secure_url, width, height }) => ({ secure_url, width, height }));\n\n console.clear();\n console.log(`About to process ${chalk.green(images.length)} images`);\n\n for (const image of images) {\n const imgData = await getPixels(image.secure_url);\n\n const data = Uint8ClampedArray.from(imgData.data);\n\n const blurhash = encode(data, imgData.width, imgData.height, 4, 4);\n\n const urlPrts = image.secure_url.split('/');\n\n blurhashImages.push({\n id: urlPrts.slice(-1)[0],\n url: image.secure_url,\n blurhash,\n width: image.width,\n height: image.height,\n });\n\n const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime));\n\n updateLogs(\n chalk.green.bold(`${percentage(blurhashImages.length, images.length)}%`),\n chalk.green.bold(`${images.length - blurhashImages.length}`),\n chalk.green.bold(`${blurhashImages.length}`),\n chalk.green.bold(elapsedSeconds),\n );\n }\n\n console.log(chalk.blue(`writing results to ${outFile}`));\n\n writeFile(outFile, JSON.stringify(blurhashImages));\n}\n","import { createCommand } from 'commander';\nimport { generateBlurhashFile } from './generateBlurhashFile';\n\nexport const program = createCommand('generate-blur-hash');\n\nprogram\n .description('generate low quality placeholder (LQIP) using blurhash')\n .option('-f, --file <file>', 'the name of the the json file', './blurhash_image_map.json')\n .parse(process.argv)\n .action(async function ({ file }: { file: string }) {\n try {\n generateBlurhashFile(file);\n } catch (err) {\n console.error(err);\n process.exit(1);\n }\n })\n .parse(process.argv);\n"],"names":["promises","writeFile","fs","config","v2","secure","console","log","program","createCommand","description","option","parse","process","argv","action","async","file","fileName","startTime","hrtime","outFile","path","join","cwd","blurhashImages","images","search","expression","max_results","execute","resources","map","secure_url","width","height","clear","chalk","green","length","image","imgData","getPixels","data","Uint8ClampedArray","from","blurhash","encode","urlPrts","split","push","id","slice","url","elapsedSeconds","toFixed","a","bold","partialValue","totalValue","b","c","d","logUpdate","blue","JSON","stringify","generateBlurhashFile","err","error","exit"],"mappings":"2QAUA,MACEA,UAAUC,UAAEA,IACVC,EAEJC,IAEAC,EAAGD,OAAO,CAAEE,QAAQ,IAQpBC,Q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CAAoCC,2CAA2CC,SAyCxG,CA3CgB,IAACN,EAAYI,EAAYC,EAAYC,EAPpCJ,EAAsBC,EAEZvC,EAkD5Bd,QAAQC,IAAI8B,EAAM2B,KAAK,sBAAsB3C,MAE7CpB,EAAUoB,EAAS4C,KAAKC,UAAUzC,GACpC,CCtEM0C,CAAqBlD,EACtB,CAAC,MAAOmD,GACP9D,QAAQ+D,MAAMD,GACdvD,QAAQyD,KAAK,EACd,CACH,IACC1D,MAAMC,QAAQC"}
@@ -0,0 +1,41 @@
1
+ export interface SubFolder {
2
+ folders: {
3
+ path: string;
4
+ }[];
5
+ }
6
+ export type AssetType = 'image';
7
+ export interface Resource {
8
+ asset_id: string;
9
+ public_id: string;
10
+ folder: string;
11
+ filename: string;
12
+ format: 'jpg' | 'png';
13
+ version: number;
14
+ resource_type: 'image' | 'video';
15
+ type: 'upload';
16
+ created_at: string;
17
+ uploaded_at: string;
18
+ bytes: number;
19
+ backup_bytes: number;
20
+ width: number;
21
+ height: number;
22
+ aspect_ratio: number;
23
+ pixels: number;
24
+ url: string;
25
+ secure_url: string;
26
+ status: 'active';
27
+ access_mode: 'public';
28
+ }
29
+ export interface SearchResults {
30
+ total_count: number;
31
+ time: number;
32
+ resources: Resource[];
33
+ }
34
+ export interface BlurHashImage {
35
+ id: string;
36
+ url: string;
37
+ blurhash: string;
38
+ width: number;
39
+ height: number;
40
+ }
41
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC7B;AAED,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC;AAEhC,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,KAAK,GAAG,KAAK,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,OAAO,GAAG,OAAO,CAAC;IACjC,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,QAAQ,CAAC;IACjB,WAAW,EAAE,QAAQ,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@cutting/cloudinary-blurhash",
3
+ "version": "0.1.1",
4
+ "description": "Generate blurhash for each image and generate a file",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/dagda1/cuttingedge.git"
8
+ },
9
+ "module": "dist/esm/index.js",
10
+ "bin": "./tools/bin/cutting.js",
11
+ "type": "module",
12
+ "sideEffects": false,
13
+ "types": "dist/esm/index.d.ts",
14
+ "keywords": [],
15
+ "author": "Paul Cowan <paul.cowan@cutting.scot>",
16
+ "dependencies": {
17
+ "@unpic/pixels": "^1.2.0",
18
+ "blurhash": "^2.0.5",
19
+ "chalk": "^5.3.0",
20
+ "cloudinary": "^1.41.0",
21
+ "dotenv": "^16.3.1",
22
+ "log-update": "^5.0.1"
23
+ },
24
+ "devDependencies": {
25
+ "commander": "11.0.0",
26
+ "eslint": "8.47.0",
27
+ "typescript": "5.1.6",
28
+ "@cutting/devtools": "4.63.3",
29
+ "@cutting/eslint-config": "4.44.1",
30
+ "@cutting/tsconfig": "4.40.1",
31
+ "@cutting/useful-types": "4.40.1"
32
+ },
33
+ "files": [
34
+ "dist/**/*",
35
+ "test.md"
36
+ ],
37
+ "volta": {
38
+ "extends": "../../package.json"
39
+ },
40
+ "exports": {
41
+ "import": "./dist/esm/index.js"
42
+ },
43
+ "typesVersions": {
44
+ "*": {
45
+ "*": [
46
+ "dist/esm/index.d.ts"
47
+ ]
48
+ }
49
+ },
50
+ "scripts": {
51
+ "build": "NODE_ENV=production devtools rollup",
52
+ "lint": "eslint ./src/**/*.ts --fix",
53
+ "start": "echo no demo yet",
54
+ "test": "echo not tests yet",
55
+ "test:ci": "echo no tests yet"
56
+ }
57
+ }