Coder Social home page Coder Social logo

perspective.js's Introduction

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.

perspective.js's People

Contributors

flozz avatar

Stargazers

 avatar  avatar  avatar crapthings avatar Christian Genco avatar  avatar Pari Nannapaneni avatar Big Totoro avatar  avatar  avatar  avatar Dmitriy Sychevskiy avatar  avatar Sartrey Lee avatar  avatar Onur Savas avatar Cédric Lahouste avatar  avatar MrRedBeard avatar Evan avatar chieh lee avatar Md. Abu Taher avatar LuckyMind avatar Pablo Martin avatar Neo avatar Mohamed Thalib avatar MAKYENI avatar Marcel Göllen avatar Dirk Arnez avatar Alex Susin Perancho avatar Carl Craig avatar Shaun Janssens avatar Nadine Ferreira  avatar  avatar  avatar  avatar  avatar Ayoub avatar Alois Odhiambo avatar Harvey Shi avatar Mutlaq Aldhbuiub avatar TigerYoo avatar Donghun Kim avatar Jeroen van Grondelle avatar ants avatar Jack Watling avatar  avatar myxvisual avatar Atahan Tuncer avatar Capsion avatar Gota Gando avatar Senjosei avatar  avatar Michael avatar Yan Ma avatar Jonny Shen avatar José Rigoni Jr avatar yding avatar  avatar Eoin avatar CodeCook avatar Casey Holzer avatar Jônatas Araújo avatar Christian Renninger avatar Kipp Ashford avatar André Ekeberg avatar Tanju Yıldız avatar 吴跃展 avatar Michael Jett avatar Bruno Belarmino de Queiroz avatar  avatar  avatar Bob Davies avatar Jordi avatar G_choke avatar Kentaro Yamamoto avatar Davide Mauri avatar Jimmy avatar Jiri Dohnalek avatar  avatar Alexander Alexandrov avatar Dmitriy (Dima) Rozhkov avatar Thousif Jowhar avatar Davi Teodoro avatar Marc avatar Kenny Hartono avatar Rui Luo avatar  avatar Oleksandr Bilousov avatar Jan Oelze avatar  avatar JunHyeok Ha avatar David Oti avatar  avatar Francesco Corbi avatar David Zhou avatar  avatar Daniel Liu avatar Marte avatar Sylvester Aswin avatar

Watchers

Mohamed Thalib avatar Anthony Colas avatar Côme avatar timelyportfolio avatar James Cloos avatar  avatar Eric  avatar Michael Anthony avatar Platane avatar  avatar  avatar François Deléglise avatar Adrien Bouttier avatar Valentin Ledrapier avatar Corentin Baur avatar Andrey avatar  avatar mache avatar  avatar  avatar

perspective.js's Issues

Image disappears when you try to flip the image.

First, just wanted to say thank you for this awesome script. This is the only one I could find that does a great job at perspective transform without any external libraries!
I have one little problem though. When the image is flipped horizontally or vertically, it just disappears.
Example: drag 2 left points to the right of the right points (flipping the points horizontally).
Ability to flip the image is crucial for my project and I just can't figure this out.
Any help appreciated.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

can't render out picture

let's say we do a rotate(120deg), then get the points look like as below. The photo not be rendered.

qq 20150728131920

Clearing active canvas problem

When I try to draw an image on my canvas, It immediately clears all the things on my canvas and after draws the image, I tried to find the source of the problem by the way I remove this line of code and it works now.

this._applyMask(this.p.ctxd, [[d0x, d0y], [d1x, d1y], [d2x, d2y], [d3x, d3y]]);

Flip & Mirror Error

I do some maths but couldnt figured out. I want to draw 2 images. First one is perfect with perspective as i wanted but second should be flipped or mirrored. When i change the coordinates for flipped image disappear or broken pixels. Anyone have a solution for this? Mirrored and perspective :S

PNG Image perspective with shadow change error

I am try to change the perspective of the png image which have small shadow on but after applying the perspective the shadow level getting increased.
download
I It is my output image
download (1)
this my input image

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.