1.2.0 • Published 2 years ago
blurhash-map v1.2.0
blurhash-map
blurhash-map
Install
npm install blurhash-mapUsage
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