Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Carapace makes it easy to create reusable image editing operations. For example:
Operations can be combined as needed, and shared in the browser and on the server.
Load an image into Carapace and run some operations on it:
var Carapace = require('carapace')
var Crop = require('carapace-crop')
Carapace
.create(imageEl)
.run([
Crop.create({ width: 100, height: 100, left: 100, top: 100 })
], function(err, canvas){
canvas // [object HTMLCanvasElement 100x100]
})
Jobs and Filters are reusable canvas operations created with Carapace.Job.extend()
and Carapace.Filter.extend()
, respectively. Extend these objects to create custom canvas operations and we'll publish them here.
COMING SOON
Carapace for node.js depends on node-canvas
which depends on some other stuff. IMPORTANT Follow the installation instructions for your system prior to installing Carapace.
Once you've installed the dependencies, install Carapace with npm:
$ npm install carapace
Download:
Carapace.register()
Carapace.create()
Canvas.create()
Font.create()
Image.create()
Job.extend()
Filter.extend()
Queue.create()
util
register(string|fn|arr)
Registers a job with Carapace. This method will pre-load and cache jobs for later use. All jobs should be registered at the start of the app.
Carapace.register('./your-filter')
Carapace.register(YourJob)
Carapace.register([
YourOtherJob,
'./your-other-filter'
])
create([imageEl|canvasEl|buffer|canvas|carapace])
Creates a carapace
object.
In node.js:
fs.readFile('./your-image.png', function(err, buf){
Carapace.create(buf)
})
Carapace.create(Carapace.Canvas.create())
In the browser:
Carapace.Image
.create('your-image.png')
.load(function(err, image){
Carapace.create(image)
})
Carapace.create(document.getElementById('your-canvas'))
carapace.run(queue|arr[, callback])
Executes a job queue on a carapace
object. This method is asynchronous and will invoke an optional callback when execution is complete.
carapace.run(queue, function(err, canvas){
// done!
})
carapace.run([
{ id: 'resize', options: { width: 500 } }
], function(err, canvas){
// done!
})
Canvas.create([imageEl|canvasEl|buffer|canvas|carapace])
Creates a canvas
.
var canvas = Carapace.Canvas.create()
Font.create(family, src[, weight][, style])
Creates a Font
for node-canvas
.
var font = Carapace.Font.create('Open Sans', './path/to/your-font.ttf')
Image.create(src|buffer)
Creates an image
.
var image = Carapace.Image.create('your-image.png')
Job.extend(options)
Extends the Job
object. Extend Job
to define general canvas manipulations.
The options
object should have the following properties:
id
String
(required) A unique identifier for the job.runSync
Function
A synchronous canvas manipulation. Should return a Canvas
.run
Function
An asynchronous canvas manipulation. Accepts avar YourJob = Carapace.Job.extend({
id: 'your-job',
runSync: function (canvas, options) {
return canvas
},
run: function (canvas, options, callback) {
return callback(null, canvas)
}
})
Filter.extend(options)
Extends the Filter
object. Extend Filter
to define pixel-wise canvas manipulations.
The options
object should have the following properties:
id
String
(required) A unique identifier for the filter.pixel
Function
An RGBA pixel manipulation. Should return an Array
of RGBA values.var YourFilter = Carapace.Filter.extend({
id: 'your-job',
pixel: function (r, g, b) {
return [255, 255, 255, 255]
}
})
Queue.create([arr])
Creates a queue
object. Optionally accepts a serialized queue array.
var queue = Carapace.Queue.create([{
id: 'resize',
options: { width: 500 }
}])
queue.add(id[, options]|job)
Adds a job to the end of the queue.
queue
.add('resize', { width: 500 })
.add(Sepia.create({ adjust: 50 }))
queue.remove()
Removes a job from the end of the queue.
queue.remove()
queue.serialize()
Serializes a queue to an array of jobs.
var arr = queue.serialize() // [{ id: 'resize', options: { width: 500 } }]
uil.compare(canvas, canvas)
Compares two canvas. Returns true
if the canvases have idential contents.
Carapace.util.compare(canvasA, canvasB) // true
uil.isCanvas(obj)
Returns true
if the object is a Canvas
.
Carapace.util.isCanvas(canvasA) // true
uil.isCarapace(obj)
Returns true
if the object is a Carapace
.
Carapace.util.isCarapace(yourCarapace) // true
uil.isImage(obj)
Returns true
if the object is an Image
.
Carapace.util.isImage(yourImage) // true
Run the example server at http://127.0.0.1:3000:
$ npm run example
$ grunt test
$ grunt test:server
$ grunt test:browser
Build standalone dist/carapace.js
and dist/carapace.min.js
files:
$ grunt dist
MIT License, see LICENSE for details.
FAQs
Manipulate images with JavaScript
The npm package carapace receives a total of 0 weekly downloads. As such, carapace popularity was classified as not popular.
We found that carapace demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.