npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

use-gif-watermark

v0.1.9

Published

Downloads

20

Readme

use-gif-watermark

usage

installation

use yarn

yarn add use-gif-watermark

or use npm

npm i use-gif-watermark
import React, { useState } from "react";
import useGifWatermark from 'use-gif-watermark'

function Example() {
  const [watermark, setWatermark] = useState(null);
  const [img, setImg] = useState(null);

   const {
    base64,
    apply,
    download,
    gifFile,
    reset,
    status,
  } = useGifWatermark({
    gifSrc: img,
    watermarkSrc: watermark,
    position: "bottomright",
    watermarkHeight: 50,
    watermarkOpacity: 1,
    watermarkWidth: 50,
    downloadOnComplete: true,
    onError({ errorMessage }) {
      console.log(errorMessage);
    },
    onStart() {
      console.log("converting started");
    },
    onSuccess({ base64, file }) {
      console.log({ base64, file });
    },
  });

  return (
    <>
      <div>
        {img && <img height={50} width={50} src={img} alt="to be converted" />}
        <input
          type="file"
          accept="image/gif"
          onChange={(e) => {
            const files = e.target.files;
            if (files && files[0] !== null) {
              setImg(URL.createObjectURL(files[0]));
            }
          }}
        />
      </div>
      <div>
        {watermark && (
          <img height={50} width={50} src={watermark} alt="watermark" />
        )}
        <input
          type="file"
          accept="image/*"
          onChange={(e) => {
            const files = e.target.files;
            if (files && files[0] !== null) {
              setWatermark(URL.createObjectURL(files[0]));
            }
          }}
        />
        <div>
          {base64 && (
            <img height={100} width={100} src={base64} alt="Converted GIF" />
          )}
          <span>Applied watermark</span>
        </div>
        <div>
          <span>{status}</span>
          <button onClick={download}>download</button>
          <button onClick={apply}>apply</button>
          <button onClick={reset}>reset</button>
        </div>
      </div>
    </>
  );
}

Props accepted for useGifWatermark

| prop |required | description |accepted value|default value| | :---------------- | :------: | :----: | :----: |:----: | |gifSrc | True |URL of the GIF | URL | | |watermarkSrc | True | URL of the watermark| URL | | | watermarkHeight | False | height of the watermark height |number | 50 | | watermarkWidth | False | width of the watermark height |number | 50 | | watermarkOpacity | False | opacity of the watermark height |number | 1 | | downloadOnComplete | False | opacity of the watermark height |boolean | false | | onError | False | |boolean | ({errorMessage})=>{} | | onStart | False | |boolean | ()=>{} | | onSuccess | False | |boolean | ({ base64, file })=>{base64 -> base64 of the watermark applied GIF,file -> GIF File} |

values returned by useGifWatermark

| prop | description |value type | | :---------------- | :----: | :----: | | base64 | base64 of the new GIF | can be base64,null or undefined | | gifFile | new GIF file | can be File,null or undefined |
| apply | applies watermark to the GIF | function |
| reset | resets all the value | function |
| download | downloads the new GIF | function |
| status | status | can be idle,converting,converted,failed,error |

Special thanks to

This library wouldn't have been possible without the help of gifshot and gifuct-js