Skip to content

adonmo/perspective.ts

 
 

Repository files navigation

perspective.ts

npm npm type definitions GitHub

perspective.ts is a TypeScript 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.

perspective.ts is a fork of perspective.js, which is itself a derivative work of the original Futomi Hatano's perspective.js

Codesandbox demo

https://codesandbox.io/s/perspectivets-demo-upqfy

Usage

<script src="../dist/perspectivets.min.js"></script>
var p = new Perspective(ctx, image);
p.draw({
  topLeftX: 30,
  topLeftY: 30,
  topRightX: 462,
  topRightY: 50,
  bottomRightX: 442,
  bottomRightY: 482,
  bottomLeftX: 10,
  bottomLeftY: 512,
});

ES5 (also supports typescript)

import Perspective from "perspectivets"

let p = new Perspective(ctx, img)
p.draw({
  topLeftX: 30,
  topLeftY: 30,
  topRightX: 462,
  topRightY: 50,
  bottomRightX: 442,
  bottomRightY: 482,
  bottomLeftX: 10,
  bottomLeftY: 512,
})

Development

Building

yarn build

Testing

No automated tests. But you can manually test using the demo:

http-server

And then open http://localhost:8080/demo/ in your browser.

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.

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 85.0%
  • JavaScript 15.0%