Git Product home page Git Product logo

stickerify's Introduction

stickerify

Add sticker-like border effect to images with transparency

Input:

input image

Output:

stickerified image

Live Demo

Check out this codepen demo: https://codepen.io/markus-wa/pen/eYEMvxd - thanks to @pento for letting me steal this!

Install

yarn add stickerify

or

npm install stickerify

Sample code

Stickerify can run in a web browser, or in a Node.js environment. For Node.js, you should use the canvas module for image loading, as this is what Stickerify uses internally for image processing.

HTML

<img id="out" />
const img = new Image(),
	out = document.getElementById('out');

img.crossOrigin = 'anonymous';
img.onload = () => {
	out.src = stickerify(img, 3, 'white').toDataURL();
};
img.src = 'https://raw.githubusercontent.com/markus-wa/stickerify/main/example/input.png';

When run in the browser, stickerify() returns a HTML5 canvas element.

Node.js

const { stickerify } = require('stickerify');
const { loadImage } = require('canvas');
const { writeFile } = require('fs');

loadImage('https://raw.githubusercontent.com/markus-wa/stickerify/main/example/input.png')
	.then((image) => stickerify(image, 3, 'white'))
	.then((image) => stickerify(image, 1, 'grey'))
	.then((canvas) => writeFile('output.png', canvas.toBuffer(), (err) => console.log(err || 'done')));

When run in Node.js, stickerify() returns a Canvas object.

stickerify's People

Contributors

dependabot[bot] avatar markus-wa avatar pento avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stickerify's Issues

Suggestion: Provide a Promise-based interface

While working with Stickerify, I've found that I frequently want to perform multiple operations on the image, it gets super verbose to be making Image objects every step of the way. I've been using a small Promise wrapper to fix this:

const promiseStickerify = ( imgSrc, size, color ) => {
	return new Promise( ( resolve, reject ) => {
		const image = new Image();
		image.onload = () => resolve( stickerify( image, size, color ) );
		image.onerror = ( e ) => reject( e );
		image.src = imgSrc;
	} );
};

It can then be used like so:

const paddedImage = await stickerify( imgURL, 15, 'white' )
	.then( ( img ) => stickerify( img.toDataURL(), 3, 'grey' ) );

This is a bit of a departure from how the library currently works, so I didn't want to open a PR without discussing it first. ๐Ÿ™‚

Images are trimmed a little too aggressively

This is a super neat little package, thanks for making it available! ๐Ÿ™‚

Whilst testing it out, I noticed a bug where it seems like the trim is a little too aggressive, taking an extra row of pixels from the right/bottom. The behaviour becomes very noticeable when running stickerify twice on the same image.

Here's a demo where you can see the bug in action: https://codepen.io/pento/pen/NWvYpRe

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.