• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Transforms the perspective of an image and draw it on a canvas

perspective.js

Github npm Discord License

perspective.js is a JavaScript library which allow you to transform a rectangle image into an arbitrary form of quadrilateral on a canvas element. It is used to draw an image using perspective on a canvas.

This is a derivative work of the original Futomi Hatano's perspective.js available on www.html5.jp still available on Internet Archive.

Install from NPM

npm install perspectivejs

Example usage

    // ctx (CanvasRenderingContext2D): The 2D context of a HTML5 canvas element.
    // image (Image): The image to transform.
    var p = new Perspective(ctx, image);
    p.draw([
        [30, 30],                               // Top-left [x, y]
        [image.width - 50, 50],                 // Top-right [x, y]
        [image.width - 70, image.height - 30],  // bottom-right [x, y]
        [10, image.height]                      // bottom-left [x, y]
    ]);

Preview

See demo/index.html for the complete example.

See also

Building the dist files

To build the files of the dist/ folder, just use the following command:

npm install
npx grunt

Changelog

  • v1.0.3: Use a clip path instead of a mask to avoid clearing the canvas (#9)
  • v1.0.2: Documentation update (install from NPM, badges)
  • v1.0.1: Documentation update
  • v1.0.0: Initial release

License

Copyright 2010 futomi  http://www.html5.jp/

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

yoga

Converts and optimizes images and 3D models
Python
99
star
2

babylon-navigation-mesh

A library to move on navigation mesh with BABYLON.js
JavaScript
73
star
3

PhotonUI

A javascript framework to create user interfaces
JavaScript
62
star
4

pyguetzli

Python bindings for Google's Guetzli, a JPEG encoder that optimises JPEG compression
C++
45
star
5

wanaprez

Simply turns Markdown into presentation
JavaScript
37
star
6

mozjpeg-lossless-optimization

Python library to optimize JPEGs losslessly using MozJPEG
Python
35
star
7

gltf-bounding-box

Computes the global bounding box of a gltf model
JavaScript
20
star
8

holes-in

A javascript library to generate 3D mesh from a 2D outer path and 2D inner paths
JavaScript
18
star
9

abitbol

The classiest javascript class library of the world
JavaScript
16
star
10

imagequant-python

Python bindings for libimagequant
Python
16
star
11

collision-gjk-epa

Fast collision detection and response for BabylonJS
JavaScript
16
star
12

obsidian-http-request

Helper library to download assets (ajax) directly or through a proxy
JavaScript
14
star
13

WanaplanAPI

Wanaplan's API documentation
10
star
14

snappy-canvas

Canvas where everything is snapped to nearest pixel
JavaScript
9
star
15

obsidian-api

Integration API for Wanadev's obsidian projects
JavaScript
9
star
16

browserify-licenses

Extracts licenses of third party modules used in a browserify bundle
JavaScript
8
star
17

git-lfs-lock-pre-commit-hook

A pre-commit hook to avoid committing locked files (for Git LFS users)
Python
8
star
18

pontoon-debian

Installing Pontoon on Debian and Ubuntu
Shell
8
star
19

changelogify

A basic changelog manager made to avoid conflicts at git merge
JavaScript
6
star
20

obsidianjs

The ObsidianJS Framework
JavaScript
5
star
21

obsidian-file

Library and CLI tool to read and write the Obsidian Project file format
JavaScript
4
star
22

obsidian-project

Library to manage Wanadev's obsidian projects
JavaScript
4
star
23

fiftysent

Partage de gros fichiers par email. Code PHP. Développé par Wanadev
PHP
4
star
24

OctoBoy

VR on GameBoy
C
3
star
25

zabbix-agent-extension-couchdb3

Zabbix extension to monitor CouchDB 3
Python
3
star
26

hermes-worker

A simple lib for WebWorker
JavaScript
3
star
27

cursorlib

Generates cursors from canvas (even '.cur' compatible with MSIE)
JavaScript
3
star
28

saltimbanque

Provides a simple Web API to convert web pages to PDF and PNG using WeasyPrint
Python
2
star
29

obsidianjs-starter

JavaScript
2
star
30

photonui-site

PhotonUI Website
HTML
2
star
31

microjs

MicroJS aka ujs is a micro Framework for JavaScript
JavaScript
2
star
32

css-var-parser

Extracts CSS variable and export them to a JavaScript object
JavaScript
2
star
33

grunt-strex

Grunt plugin to extract strings from javascript files, process them and export them all to an other file.
JavaScript
1
star
34

webpack-stonejs

Webpack Plugin for Stone.js
JavaScript
1
star
35

wanadev.github.io

Wanadev Page
1
star
36

bench-mysql-psql

PHP
1
star
37

unreal-colorblind-tool

1
star
38

tinu

Simple unit convertor library with zero dependency
JavaScript
1
star
39

wanashare

Share medias on Twitter and Facebook
JavaScript
1
star
40

liv-mask-tool

A VR tool to create world-space garbage masks for LIV Mixed Reality
C#
1
star
41

jsdoc-plugin-abitbol

A jsdoc plugin which simplifies abitbol classes documentation.
JavaScript
1
star
42

lava.ts-serializable

Typescript classes for data serialization
TypeScript
1
star
43

generator-photonui-widget

Yeoman PhotonUI widget generator.
JavaScript
1
star