Code Monkey home page Code Monkey logo

cloudinary-blurhash's Introduction

Cloudinary BlurHash

Introduction

Cloudinary BlurHash is a project that will generate a JSON file mappig your Cloudinary images, with their blurhash equivalent.

How it works

This project consist of 3 scripts:

  • transformer/index.js ( AKA the server ).
  • map.js will map your cloudinary images to their blurhash
  • context.js will add the blurhash as context of your image meta-data

⚠️ For the map.js, you'll have to create the file data/map.json manually before running the project.

Run the project

You'll need to have a Cloudinary account, and you'll need get your Cloudinary CLOUD_NAME, API_KEY and API_SECRET and add them to the .env ( See .env.example).

You can also add a PORT variable, if you have any preference, otherwise it'll fallback on the port 5000.

Once you've got your .env ready, open two terminals:

  • 1️⃣ Start the server: yarn server
  • 2️⃣ Start the fetch yarn start

SERVER

The server is a simple express server that got 2 different endpoints:

  • /transform will process your image live ( beware, it's slow )
  • /context will return the blurhash metadata from your image

To pass it an image, use the q parameter: localhost:8080/transform/?q=<imageUrl> or localhost:8080/context/?q=<imageUrl>

for this query: http://localhost:8080/context/?q=https://res.cloudinary.com/hilnmyskv/image/upload/v1528201739/algolia_logo.png; the /context endpoint will respond with:

"Ug97[f%Qx{tUj=j]j^j?M[R=WGWZbKaxa$ax"

for this query: http://localhost:8080/transform/?q=https://res.cloudinary.com/hilnmyskv/image/upload/v1528201739/algolia_logo.png; the /transform endpoint will respond with:

{
  "hash": "Ug97[f%Qx{tUj=j]j^j?M[R=WGWZbKaxa$ax",
  "processed_in_ms": 95
}

Informations

BlurHash?

Learn more about BlurHash

Test your BlurHash in our online playground: https://blurhash-sandbox.surge.sh/

Credits

This project uses the Cloudinary NodeJS SDK and BlurHash (TypeScript).

Thanks to my dear colleague @Haroenv for his help on improving the final script.

cloudinary-blurhash's People

Contributors

haroenv avatar lukyvj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

haroenv

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.