Added ratio to (open)

This commit is contained in:
Devine Lu Linvega
2019-07-27 16:09:54 +09:00
parent 3c1ff57caa
commit 98e4e5a825
3 changed files with 10 additions and 10 deletions

View File

@@ -13,8 +13,8 @@ function Library (ronin) {
return path
}
this.open = async (path) => { // Imports a graphic file and resizes the frame.
return ronin.surface.open(path)
this.open = async (path, ratio = 1) => { // Imports a graphic file and resizes the frame.
return ronin.surface.open(path, ratio)
}
// Transforms

View File

@@ -121,15 +121,15 @@ function Surface (ronin) {
// IO
this.open = function (path) {
this.open = function (path, ratio = 1) {
return new Promise(resolve => {
const img = new Image()
img.src = path
img.onload = () => {
ronin.log(`Open ${img.width}x${img.height}`)
const rect = { x: 0, y: 0, w: img.width, h: img.height }
const rect = { x: 0, y: 0, w: parseInt(img.width * ratio), h: parseInt(img.height * ratio) }
ronin.log(`Open ${rect.w}x${rect.h}`)
this.resize(rect, true)
this.context.drawImage(img, 0, 0, img.width, img.height)
this.context.drawImage(img, 0, 0, rect.w, rect.h)
resolve()
}
})