@cutting/cloudinary-blurhash 0.1.1 → 0.1.2
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.
- package/README.md +50 -0
- package/bin/index.mjs +3 -0
- package/dist/esm/generateBlurhashFile.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -3
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @cutting/cloudinary-blurhash
|
|
2
|
+
|
|
3
|
+
Cloudinary BlurHash will generate a JSON file mappig your Cloudinary images, with their blurhash equivalent.
|
|
4
|
+
|
|
5
|
+
e.g.
|
|
6
|
+
|
|
7
|
+
```JSON
|
|
8
|
+
[
|
|
9
|
+
{
|
|
10
|
+
"id": "image_hash.png",
|
|
11
|
+
"url": "https://res.cloudinary.com/ddospxsc8/image/upload/v11/image_hash.png",
|
|
12
|
+
"blurhash": "U25Y1#_4xT-;NO-=?a%MV?j[o#WB?EW9ItM{",
|
|
13
|
+
"width": 600,
|
|
14
|
+
"height": 404
|
|
15
|
+
},
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Declare the `CLOUDINARY_URL` environment variable that takes this format.
|
|
21
|
+
|
|
22
|
+
```shell
|
|
23
|
+
export CLOUDINARY_URL=cloudinary://<API_KEY>:<CLOUDINARY_API_SECRET>@<CLOUDINARY_CLOUD_NAME>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Run
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
npx @cutting/cloudinary-blurhash
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Switches
|
|
33
|
+
|
|
34
|
+
- `-f` or `--file`, the file name and path to the JSON output. Default is `<CWD>/blurhash_image_map.json`
|
|
35
|
+
|
|
36
|
+
e.g.
|
|
37
|
+
|
|
38
|
+
```shell
|
|
39
|
+
npx @cutting/cloudinary-blurhash -f ./app/json/blurhash_image_map.json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This package creates a [bin script](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin) that can be executed like this:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
npx @cutting/cloudinary-blurhash
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Your console should look something like this:
|
|
49
|
+
|
|
50
|
+

|
package/bin/index.mjs
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateBlurhashFile.d.ts","sourceRoot":"","sources":["../../src/generateBlurhashFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateBlurhashFile.d.ts","sourceRoot":"","sources":["../../src/generateBlurhashFile.ts"],"names":[],"mappings":"AA2BA,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkD1E"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createCommand as e}from"commander";import{v2 as
|
|
1
|
+
import{createCommand as e}from"commander";import{v2 as r}from"cloudinary";import o from"fs";import{getPixels as s}from"@unpic/pixels";import{encode as t}from"blurhash";import i from"chalk";import n from"log-update";import c from"path";const{promises:{writeFile:l}}=o,a=e("generate-blur-hash");a.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){try{const d=process.hrtime(),f=c.join(process.cwd(),e),b=[],w=(await r.search.expression("format=(NOT ico and NOT gif)").max_results(1e3).execute()).resources.map((({secure_url:e,width:r,height:o})=>({secure_url:e,width:r,height:o})));console.clear(),console.log(`About to process ${i.green(w.length)} images`);for(const e of w){const r=await s(e.secure_url),c=Uint8ClampedArray.from(r.data),l=t(c,r.width,r.height,4,4),f=e.secure_url.split("/");b.push({id:f.slice(-1)[0],url:e.secure_url,blurhash:l,width:e.width,height:e.height});const x=((u=process.hrtime(d))[0]+u[1]/1e9).toFixed(3);o=i.green.bold(`${g=b.length,m=w.length,(100*g/m).toFixed(2)}%`),a=i.green.bold(""+(w.length-b.length)),h=i.green.bold(`${b.length}`),p=i.green.bold(x),n(`\n${o} Processed.\n\n${a} images remaining to process\n\n${h} images processed ✅\n\nProcess started ${p}s ago`)}console.log(i.blue(`writing results to ${f}`)),l(f,JSON.stringify(b))}catch(e){console.error(e)}var o,a,h,p,g,m,u}(e)}catch(e){console.error(e),process.exit(1)}})).parse(process.argv);export{a as program};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/generateBlurhashFile.ts","../../src/index.ts"],"sourcesContent":["import { v2 } from 'cloudinary';\nimport fs from 'fs';\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/generateBlurhashFile.ts","../../src/index.ts"],"sourcesContent":["import { v2 } from 'cloudinary';\nimport fs from 'fs';\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\n// console.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 try {\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\n .expression('format=(NOT ico and NOT gif)')\n .max_results(1000)\n .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 urlParts = image.secure_url.split('/');\n\n blurhashImages.push({\n id: urlParts.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 } catch (err) {\n console.error(err);\n }\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","program","createCommand","description","option","parse","process","argv","action","async","file","fileName","startTime","hrtime","outFile","path","join","cwd","blurhashImages","images","v2","search","expression","max_results","execute","resources","map","secure_url","width","height","console","clear","log","chalk","green","length","image","imgData","getPixels","data","Uint8ClampedArray","from","blurhash","encode","urlParts","split","push","id","slice","url","elapsedSeconds","toFixed","a","bold","partialValue","totalValue","b","c","d","logUpdate","blue","JSON","stringify","err","error","generateBlurhashFile","exit"],"mappings":"2OASA,MACEA,UA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AAoCC,2CAA2CC,SA6CtG,CAED5B,QAAQE,IAAIC,EAAM2B,KAAK,sBAAsB9C,MAE7Cf,EAAUe,EAAS+C,KAAKC,UAAU5C,GACnC,CAAC,MAAO6C,GACPjC,QAAQkC,MAAMD,EACf,CAtDgB,IAACX,EAAYI,EAAYC,EAAYC,EAPpCJ,EAAsBC,EAEZ1C,CA4D9B,CClEMoD,CAAqBvD,EACtB,CAAC,MAAOqD,GACPjC,QAAQkC,MAAMD,GACdzD,QAAQ4D,KAAK,EACd,CACH,IACC7D,MAAMC,QAAQC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cutting/cloudinary-blurhash",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Generate blurhash for each image and generate a file",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/dagda1/cuttingedge.git"
|
|
8
8
|
},
|
|
9
9
|
"module": "dist/esm/index.js",
|
|
10
|
-
"bin": "./
|
|
10
|
+
"bin": "./bin/index.mjs",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"types": "dist/esm/index.d.ts",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"blurhash": "^2.0.5",
|
|
19
19
|
"chalk": "^5.3.0",
|
|
20
20
|
"cloudinary": "^1.41.0",
|
|
21
|
-
"dotenv": "^16.3.1",
|
|
22
21
|
"log-update": "^5.0.1"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|