Added (crop), fixes #29
This commit is contained in:
parent
79f85782ab
commit
e9a84b376a
@ -43,6 +43,11 @@ function Library (ronin) {
|
||||
return rect
|
||||
}
|
||||
|
||||
this.crop = (rect, callback) => {
|
||||
ronin.surface.crop(rect, callback)
|
||||
return rect
|
||||
}
|
||||
|
||||
this.exit = () => {
|
||||
// TODO: Closes Ronin
|
||||
}
|
||||
|
@ -136,6 +136,13 @@ function Surface (ronin) {
|
||||
}
|
||||
}
|
||||
|
||||
this.crop = function (rect) {
|
||||
console.log(`Crop ${rect.w}x${rect.h} from ${rect.x}x${rect.y}`)
|
||||
const crop = this.getCrop(rect)
|
||||
this.resize(rect, true)
|
||||
this.context.drawImage(crop, 0, 0)
|
||||
}
|
||||
|
||||
this.clear = function (rect = this.getFrame(), context = this.context) {
|
||||
context.clearRect(rect.x, rect.y, rect.w, rect.h)
|
||||
}
|
||||
@ -184,6 +191,14 @@ function Surface (ronin) {
|
||||
return { x: 0, y: 0, w: this.el.width, h: this.el.height, t: 'rect' }
|
||||
}
|
||||
|
||||
this.getCrop = function (rect) {
|
||||
const newCanvas = document.createElement('canvas')
|
||||
newCanvas.width = rect.w
|
||||
newCanvas.height = rect.h
|
||||
newCanvas.getContext('2d').drawImage(this.el, rect.x, rect.y, rect.w, rect.h, 0, 0, rect.w, rect.h)
|
||||
return newCanvas
|
||||
}
|
||||
|
||||
this.resizeImage = function (src, dst, type = 'image/jpeg', quality = 0.92) {
|
||||
var tmp = new Image()
|
||||
var canvas
|
||||
|
16
examples/crop.lisp
Normal file
16
examples/crop.lisp
Normal file
@ -0,0 +1,16 @@
|
||||
; crop
|
||||
|
||||
(
|
||||
(clear)
|
||||
|
||||
; Filter
|
||||
|
||||
(def filter-action
|
||||
(lambda () (crop (rect 100 100 400 400))))
|
||||
|
||||
; Draw photo
|
||||
|
||||
(open
|
||||
"../../PREVIEW.jpg"
|
||||
filter-action)
|
||||
)
|
@ -1,4 +1,4 @@
|
||||
; pixels
|
||||
; resize
|
||||
|
||||
(
|
||||
(clear)
|
||||
|
Loading…
x
Reference in New Issue
Block a user