Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@jimp/plugin-rotate

Package Overview
Dependencies
Maintainers
2
Versions
241
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jimp/plugin-rotate - npm Package Compare versions

Comparing version 0.20.2 to 0.21.0--canary.1149.3239903.0

144

dist/index.js

@@ -6,6 +6,4 @@ "use strict";

});
exports["default"] = void 0;
exports.default = void 0;
var _utils = require("@jimp/utils");
/**

@@ -18,38 +16,35 @@ * Rotates an image counter-clockwise by an arbitrary number of degrees. NB: 'this' must be a Jimp object.

deg %= 360;
var rad = deg * Math.PI / 180;
var cosine = Math.cos(rad);
var sine = Math.sin(rad); // the final width and height will change if resize == true
const rad = deg * Math.PI / 180;
const cosine = Math.cos(rad);
const sine = Math.sin(rad);
var w = this.bitmap.width;
var h = this.bitmap.height;
// the final width and height will change if resize == true
let w = this.bitmap.width;
let h = this.bitmap.height;
if (mode === true || typeof mode === "string") {
// resize the image to it maximum dimension and blit the existing image
// onto the center so that when it is rotated the image is kept in bounds
// http://stackoverflow.com/questions/3231176/how-to-get-size-of-a-rotated-rectangle
// Plus 1 border pixel to ensure to show all rotated result for some cases.
w = Math.ceil(Math.abs(this.bitmap.width * cosine) + Math.abs(this.bitmap.height * sine)) + 1;
h = Math.ceil(Math.abs(this.bitmap.width * sine) + Math.abs(this.bitmap.height * cosine)) + 1; // Ensure destination to have even size to a better result.
h = Math.ceil(Math.abs(this.bitmap.width * sine) + Math.abs(this.bitmap.height * cosine)) + 1;
// Ensure destination to have even size to a better result.
if (w % 2 !== 0) {
w++;
}
if (h % 2 !== 0) {
h++;
}
var c = this.cloneQuiet();
const c = this.cloneQuiet();
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
this.bitmap.data.writeUInt32BE(this._background, idx);
});
var max = Math.max(w, h, this.bitmap.width, this.bitmap.height);
const max = Math.max(w, h, this.bitmap.width, this.bitmap.height);
this.resize(max, max, mode);
this.blit(c, this.bitmap.width / 2 - c.bitmap.width / 2, this.bitmap.height / 2 - c.bitmap.height / 2);
}
var bW = this.bitmap.width;
var bH = this.bitmap.height;
var dstBuffer = Buffer.alloc(this.bitmap.data.length);
const bW = this.bitmap.width;
const bH = this.bitmap.height;
const dstBuffer = Buffer.alloc(this.bitmap.data.length);
function createTranslationFunction(deltaX, deltaY) {

@@ -63,15 +58,12 @@ return function (x, y) {

}
var translate2Cartesian = createTranslationFunction(-(bW / 2), -(bH / 2));
var translate2Screen = createTranslationFunction(bW / 2 + 0.5, bH / 2 + 0.5);
for (var y = 1; y <= bH; y++) {
for (var x = 1; x <= bW; x++) {
var cartesian = translate2Cartesian(x, y);
var source = translate2Screen(cosine * cartesian.x - sine * cartesian.y, cosine * cartesian.y + sine * cartesian.x);
var dstIdx = bW * (y - 1) + x - 1 << 2;
const translate2Cartesian = createTranslationFunction(-(bW / 2), -(bH / 2));
const translate2Screen = createTranslationFunction(bW / 2 + 0.5, bH / 2 + 0.5);
for (let y = 1; y <= bH; y++) {
for (let x = 1; x <= bW; x++) {
const cartesian = translate2Cartesian(x, y);
const source = translate2Screen(cosine * cartesian.x - sine * cartesian.y, cosine * cartesian.y + sine * cartesian.x);
const dstIdx = bW * (y - 1) + x - 1 << 2;
if (source.x >= 0 && source.x < bW && source.y >= 0 && source.y < bH) {
var srcIdx = (bW * (source.y | 0) + source.x | 0) << 2;
var pixelRGBA = this.bitmap.data.readUInt32BE(srcIdx);
const srcIdx = (bW * (source.y | 0) + source.x | 0) << 2;
const pixelRGBA = this.bitmap.data.readUInt32BE(srcIdx);
dstBuffer.writeUInt32BE(pixelRGBA, dstIdx);

@@ -84,60 +76,46 @@ } else {

}
this.bitmap.data = dstBuffer;
if (mode === true || typeof mode === "string") {
// now crop the image to the final size
var _x = bW / 2 - w / 2;
var _y = bH / 2 - h / 2;
this.crop(_x, _y, w, h);
const x = bW / 2 - w / 2;
const y = bH / 2 - h / 2;
this.crop(x, y, w, h);
}
}
var _default = function _default() {
return {
/**
* Rotates the image counter-clockwise by a number of degrees. By default the width and height of the image will be resized appropriately.
* @param {number} deg the number of degrees to rotate the image by
* @param {string|boolean} mode (optional) resize mode or a boolean, if false then the width and height of the image will not be changed
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
rotate: function rotate(deg, mode, cb) {
// enable overloading
if (typeof mode === "undefined" || mode === null) {
// e.g. image.resize(120);
// e.g. image.resize(120, null, cb);
// e.g. image.resize(120, undefined, cb);
mode = true;
}
if (typeof mode === "function" && typeof cb === "undefined") {
// e.g. image.resize(120, cb);
cb = mode;
mode = true;
}
if (typeof deg !== "number") {
return _utils.throwError.call(this, "deg must be a number", cb);
}
if (typeof mode !== "boolean" && typeof mode !== "string") {
return _utils.throwError.call(this, "mode must be a boolean or a string", cb);
}
advancedRotate.call(this, deg, mode, cb);
if ((0, _utils.isNodePattern)(cb)) {
cb.call(this, null, this);
}
return this;
var _default = () => ({
/**
* Rotates the image counter-clockwise by a number of degrees. By default the width and height of the image will be resized appropriately.
* @param {number} deg the number of degrees to rotate the image by
* @param {string|boolean} mode (optional) resize mode or a boolean, if false then the width and height of the image will not be changed
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
rotate(deg, mode, cb) {
// enable overloading
if (typeof mode === "undefined" || mode === null) {
// e.g. image.resize(120);
// e.g. image.resize(120, null, cb);
// e.g. image.resize(120, undefined, cb);
mode = true;
}
};
};
exports["default"] = _default;
if (typeof mode === "function" && typeof cb === "undefined") {
// e.g. image.resize(120, cb);
cb = mode;
mode = true;
}
if (typeof deg !== "number") {
return _utils.throwError.call(this, "deg must be a number", cb);
}
if (typeof mode !== "boolean" && typeof mode !== "string") {
return _utils.throwError.call(this, "mode must be a boolean or a string", cb);
}
advancedRotate.call(this, deg, mode, cb);
if ((0, _utils.isNodePattern)(cb)) {
cb.call(this, null, this);
}
return this;
}
});
exports.default = _default;
module.exports = exports.default;
//# sourceMappingURL=index.js.map

@@ -1,10 +0,3 @@

"use strict";
import { throwError, isNodePattern } from "@jimp/utils";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _utils = require("@jimp/utils");
/**

@@ -17,38 +10,35 @@ * Rotates an image counter-clockwise by an arbitrary number of degrees. NB: 'this' must be a Jimp object.

deg %= 360;
var rad = deg * Math.PI / 180;
var cosine = Math.cos(rad);
var sine = Math.sin(rad); // the final width and height will change if resize == true
const rad = deg * Math.PI / 180;
const cosine = Math.cos(rad);
const sine = Math.sin(rad);
var w = this.bitmap.width;
var h = this.bitmap.height;
// the final width and height will change if resize == true
let w = this.bitmap.width;
let h = this.bitmap.height;
if (mode === true || typeof mode === "string") {
// resize the image to it maximum dimension and blit the existing image
// onto the center so that when it is rotated the image is kept in bounds
// http://stackoverflow.com/questions/3231176/how-to-get-size-of-a-rotated-rectangle
// Plus 1 border pixel to ensure to show all rotated result for some cases.
w = Math.ceil(Math.abs(this.bitmap.width * cosine) + Math.abs(this.bitmap.height * sine)) + 1;
h = Math.ceil(Math.abs(this.bitmap.width * sine) + Math.abs(this.bitmap.height * cosine)) + 1; // Ensure destination to have even size to a better result.
h = Math.ceil(Math.abs(this.bitmap.width * sine) + Math.abs(this.bitmap.height * cosine)) + 1;
// Ensure destination to have even size to a better result.
if (w % 2 !== 0) {
w++;
}
if (h % 2 !== 0) {
h++;
}
var c = this.cloneQuiet();
const c = this.cloneQuiet();
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
this.bitmap.data.writeUInt32BE(this._background, idx);
});
var max = Math.max(w, h, this.bitmap.width, this.bitmap.height);
const max = Math.max(w, h, this.bitmap.width, this.bitmap.height);
this.resize(max, max, mode);
this.blit(c, this.bitmap.width / 2 - c.bitmap.width / 2, this.bitmap.height / 2 - c.bitmap.height / 2);
}
var bW = this.bitmap.width;
var bH = this.bitmap.height;
var dstBuffer = Buffer.alloc(this.bitmap.data.length);
const bW = this.bitmap.width;
const bH = this.bitmap.height;
const dstBuffer = Buffer.alloc(this.bitmap.data.length);
function createTranslationFunction(deltaX, deltaY) {

@@ -62,15 +52,12 @@ return function (x, y) {

}
var translate2Cartesian = createTranslationFunction(-(bW / 2), -(bH / 2));
var translate2Screen = createTranslationFunction(bW / 2 + 0.5, bH / 2 + 0.5);
for (var y = 1; y <= bH; y++) {
for (var x = 1; x <= bW; x++) {
var cartesian = translate2Cartesian(x, y);
var source = translate2Screen(cosine * cartesian.x - sine * cartesian.y, cosine * cartesian.y + sine * cartesian.x);
var dstIdx = bW * (y - 1) + x - 1 << 2;
const translate2Cartesian = createTranslationFunction(-(bW / 2), -(bH / 2));
const translate2Screen = createTranslationFunction(bW / 2 + 0.5, bH / 2 + 0.5);
for (let y = 1; y <= bH; y++) {
for (let x = 1; x <= bW; x++) {
const cartesian = translate2Cartesian(x, y);
const source = translate2Screen(cosine * cartesian.x - sine * cartesian.y, cosine * cartesian.y + sine * cartesian.x);
const dstIdx = bW * (y - 1) + x - 1 << 2;
if (source.x >= 0 && source.x < bW && source.y >= 0 && source.y < bH) {
var srcIdx = (bW * (source.y | 0) + source.x | 0) << 2;
var pixelRGBA = this.bitmap.data.readUInt32BE(srcIdx);
const srcIdx = (bW * (source.y | 0) + source.x | 0) << 2;
const pixelRGBA = this.bitmap.data.readUInt32BE(srcIdx);
dstBuffer.writeUInt32BE(pixelRGBA, dstIdx);

@@ -83,59 +70,44 @@ } else {

}
this.bitmap.data = dstBuffer;
if (mode === true || typeof mode === "string") {
// now crop the image to the final size
var _x = bW / 2 - w / 2;
var _y = bH / 2 - h / 2;
this.crop(_x, _y, w, h);
const x = bW / 2 - w / 2;
const y = bH / 2 - h / 2;
this.crop(x, y, w, h);
}
}
var _default = function _default() {
return {
/**
* Rotates the image counter-clockwise by a number of degrees. By default the width and height of the image will be resized appropriately.
* @param {number} deg the number of degrees to rotate the image by
* @param {string|boolean} mode (optional) resize mode or a boolean, if false then the width and height of the image will not be changed
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
rotate: function rotate(deg, mode, cb) {
// enable overloading
if (typeof mode === "undefined" || mode === null) {
// e.g. image.resize(120);
// e.g. image.resize(120, null, cb);
// e.g. image.resize(120, undefined, cb);
mode = true;
}
if (typeof mode === "function" && typeof cb === "undefined") {
// e.g. image.resize(120, cb);
cb = mode;
mode = true;
}
if (typeof deg !== "number") {
return _utils.throwError.call(this, "deg must be a number", cb);
}
if (typeof mode !== "boolean" && typeof mode !== "string") {
return _utils.throwError.call(this, "mode must be a boolean or a string", cb);
}
advancedRotate.call(this, deg, mode, cb);
if ((0, _utils.isNodePattern)(cb)) {
cb.call(this, null, this);
}
return this;
export default (() => ({
/**
* Rotates the image counter-clockwise by a number of degrees. By default the width and height of the image will be resized appropriately.
* @param {number} deg the number of degrees to rotate the image by
* @param {string|boolean} mode (optional) resize mode or a boolean, if false then the width and height of the image will not be changed
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
rotate(deg, mode, cb) {
// enable overloading
if (typeof mode === "undefined" || mode === null) {
// e.g. image.resize(120);
// e.g. image.resize(120, null, cb);
// e.g. image.resize(120, undefined, cb);
mode = true;
}
};
};
exports["default"] = _default;
if (typeof mode === "function" && typeof cb === "undefined") {
// e.g. image.resize(120, cb);
cb = mode;
mode = true;
}
if (typeof deg !== "number") {
return throwError.call(this, "deg must be a number", cb);
}
if (typeof mode !== "boolean" && typeof mode !== "string") {
return throwError.call(this, "mode must be a boolean or a string", cb);
}
advancedRotate.call(this, deg, mode, cb);
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
}));
//# sourceMappingURL=index.js.map
{
"name": "@jimp/plugin-rotate",
"version": "0.20.2",
"version": "0.21.0--canary.1149.3239903.0",
"description": "Rotate an image.",

@@ -24,4 +24,3 @@ "main": "dist/index.js",

"dependencies": {
"@babel/runtime": "^7.7.2",
"@jimp/utils": "^0.20.2"
"@jimp/utils": "0.21.0--canary.1149.3239903.0"
},

@@ -35,7 +34,7 @@ "peerDependencies": {

"devDependencies": {
"@jimp/custom": "^0.20.2",
"@jimp/plugin-blit": "^0.20.2",
"@jimp/plugin-crop": "^0.20.2",
"@jimp/plugin-resize": "^0.20.2",
"@jimp/test-utils": "^0.20.2"
"@jimp/custom": "0.21.0--canary.1149.3239903.0",
"@jimp/plugin-blit": "0.21.0--canary.1149.3239903.0",
"@jimp/plugin-crop": "0.21.0--canary.1149.3239903.0",
"@jimp/plugin-resize": "0.21.0--canary.1149.3239903.0",
"@jimp/test-utils": "0.21.0--canary.1149.3239903.0"
},

@@ -45,3 +44,3 @@ "publishConfig": {

},
"gitHead": "cebbdb72f889102a8e3c42b25ad3243b16e3a485"
"gitHead": "323990352ce279d67297aed097b37bd8ec66ef51"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc