@cutting/cloudinary-blurhash 0.1.5 → 0.1.6
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/dist/esm/index.js.map +1 -1
- package/package.json +9 -9
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 type { BlurHashImage, SearchResults } from './types
|
|
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,UAAUC,UAAEA,IACVC,ECRSC,EAAUC,EAAc,sBAErCD,EACGE,YAAY,0DACZC,OAAO,oBAAqB,gCAAiC,6BAC7DC,MAAMC,QAAQC,MACdC,QAAOC,gBAAgBC,KAAEA,IACxB,KDiBGD,eAAoCE,GACzC,IACE,MAAMC,EAAYN,QAAQ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,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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cutting/cloudinary-blurhash",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Generate blurhash for each image and generate a file",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,20 +14,20 @@
|
|
|
14
14
|
"keywords": [],
|
|
15
15
|
"author": "Paul Cowan <paul.cowan@cutting.scot>",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@unpic/pixels": "^1.2.
|
|
17
|
+
"@unpic/pixels": "^1.2.2",
|
|
18
18
|
"blurhash": "^2.0.5",
|
|
19
19
|
"chalk": "^5.3.0",
|
|
20
|
-
"cloudinary": "^
|
|
20
|
+
"cloudinary": "^2.0.2",
|
|
21
21
|
"log-update": "^6.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"commander": "
|
|
25
|
-
"eslint": "8.
|
|
24
|
+
"commander": "12.0.0",
|
|
25
|
+
"eslint": "8.57.0",
|
|
26
26
|
"typescript": "5.3.3",
|
|
27
|
-
"@cutting/devtools": "4.63.
|
|
28
|
-
"@cutting/eslint-config": "4.45.
|
|
29
|
-
"@cutting/tsconfig": "4.40.
|
|
30
|
-
"@cutting/useful-types": "4.40.
|
|
27
|
+
"@cutting/devtools": "4.63.6",
|
|
28
|
+
"@cutting/eslint-config": "4.45.4",
|
|
29
|
+
"@cutting/tsconfig": "4.40.5",
|
|
30
|
+
"@cutting/useful-types": "4.40.3"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"dist/**/*",
|