cutImg.js
A minimalist javascript library for cutting images into smaller rectangular sections / copying them
Command | Effect |
---|---|
cut(img, x, y, width, height) |
returns a cut version of the previous image |
split(img, tileWidth, tileHeight) |
returns a tilemap of the image based on the tilesize entered |
join(a,b,x,y) |
join two images together (2nd image is offset by x and y) |
mirror(img, x,y) |
mirror an image along one or two specified axes (if x or y = true) |
as a module module
// this file must be loaded as a module:
// <script src="path/to/cutImg.mjs" type="module"></script>
import * as CUTIMG from 'lib/cutImg/cutImg.mjs';
originalImage = new Image();
originalImage.src = "url/to/image.png";
newImage = CUTIMG.cut(originalImage, 100, 200, 450, 600);
as a script
<head>
<!-- [...] -->
<script src="path/to/cutImg.js"></script>
<!-- [...] -->
</head>
originalImage = new Image();
originalImage.src = "url/to/image.png";
newImage = cutImg(originalImage, 100, 200, 450, 600);