GithubHelp home page GithubHelp logo

suryatmodulus / blurhash-dart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from justacid/blurhash-dart

0.0 1.0 0.0 290 KB

A pure dart implementation of blurhash

License: MIT License

Dart 100.00%

blurhash-dart's Introduction

BlurHash Dart

A pure dart implementation of BlurHash without any external dependencies (except for running tests) for maximum flexibility. Supports encoding and decoding. See BlurHash website or GitHub repository for more information.

The encoder of this dart implementation produces slightly different hashes than the TypeScript implementation but matches the official C and Python implementation. In practice this should not be relevant.

Basic usage

Decoding a BlurHash

Decoding a BlurHash returns a raw array of pixels in RGBA32 format. You must convert the data to an image yourself. For this example we use the bitmap package to convert the pixel array to an bitmap, then to an ui.Image.

import 'package:blurhash_dart/blurhash_dart.dart';
import 'package:bitmap/bitmap.dart';

import 'dart:ui' as ui; // for displaying the image
//..

String blurHash = "LEHV6nWB2yk8pyo0adR*.7kCMdnj";
Uint8List pixels = decodeBlurHash(blurHash, 35, 20);

Bitmap bitmap = Bitmap.fromHeadless(35, 20, pixels);
ui.Image image = await bitmap.buildImage();
//..

Encoding a BlurHash

For demo purposes we assume to have the popular image package installed, which decodes image files. The blurhash-dart API expects raw pixels in RGBA32 format for maximum flexibility.

import 'package:blurhash_dart/blurhash_dart.dart';
import 'package:image/image.dart' as img; // for demo purposes
//..

Uint8List fileData = File("some_image.png").readAsBytesSync();
img.Image image = img.decodeImage(fileData.toList());

final blurHash = encodeBlurHash(
  image.getBytes(format: Format.rgba),
  image.width,
  image.height,
);

print("$blurHash");

blurhash-dart's People

Contributors

justacid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.