blurhash-map
v1.2.0
Published
A template for creating npm packages using TypeScript and VSCode
Downloads
8
Maintainers
Readme
blurhash-map
blurhash-map
Install
npm install blurhash-map
Usage
import { BlurHashMap, BlurHashMapConfig } from 'blurhash-map';
const config: BlurHashMapConfig = {
assetsRoot: 'assets/images/samples',
hashMapJsonPath: 'test/fixtures/lib/hashmap.json',
imageExtensions: 'jpg,png,jpeg',
components: { x: 4, y: 3 },
};
const blurHashMap = new BlurHashMap(config);
blurHashMap.init();
// Now, there should be files created next to images
// with the same name but having `.hash` suffix. You should commit these files
// to avoid re-generate them next time you run `BlurHashMap`.
API
BlurHashMap(config)
config
Type: BlurHashMapConfig
assetsRoot: string; // Required. Where to find the images hashMapJsonPath: string; // Required. Where to save generated JSON imageExtensions: Array; // Optional. Define which image files. Default : 'jpg' | 'jpeg' | 'png' | 'bmp' | 'webp' components?: { x: number; y: number }; // Optional between 1-9. Default {x:4,y:3}. Higher is more detailed blur but longer string
init()
Initialize BlurHashMap
asynchronously. Creates .hash
files and generates hash-map.json
.
generateOrDelete(imageOrHashFilePath: string, skipIfHasHash = false)
Generates a hash file if image is found. If Image is not found, deletes the .hash
file of it.
getShortPath(file: string): string
Returns the relative path of the given file
to the assetsRoot
async createJson(): Promise
Creates hash-map.json
from the found .hash
files