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

@ -40,7 +40,7 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
- `(import path shape)` Imports a graphic file with format. - `(import path shape)` Imports a graphic file with format.
- `(export path ~format ~quality)` Exports a graphic file with format. - `(export path ~format ~quality)` Exports a graphic file with format.
- `(open path)` Imports a graphic file and resizes the frame. - `(open path ~ratio)` Imports a graphic file and resizes the frame.
- `(move x y)` - `(move x y)`
- `(rotate angle)` - `(rotate angle)`
- `(scale x y)` - `(scale x y)`
@ -49,7 +49,7 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
- `(resetTransform)` - `(resetTransform)`
- `(pushTransform)` - `(pushTransform)`
- `(popTransform)` - `(popTransform)`
- `(pos x y)` Returns a position shape. - `(pos ~x ~y)` Returns a position shape.
- `(size w h)` Returns a size shape. - `(size w h)` Returns a size shape.
- `(rect x y w h)` Returns a rect shape. - `(rect x y w h)` Returns a rect shape.
- `(circle cx cy r)` Returns a circle shape. - `(circle cx cy r)` Returns a circle shape.
@ -60,7 +60,7 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
- `(stroke ~shape)` Strokes a shape. - `(stroke ~shape)` Strokes a shape.
- `(fill ~rect)` Fills a shape. - `(fill ~rect)` Fills a shape.
- `(gradient line ~colors 'black'])` Defines a gradient color. - `(gradient line ~colors 'black'])` Defines a gradient color.
- `(guide shape)` Draws a shape on the guide layer. - `(guide shape color)` Draws a shape on the guide layer.
- `(clear ~rect)` Clears a rect. - `(clear ~rect)` Clears a rect.
- `(frame)` Returns a rect of the frame. - `(frame)` Returns a rect of the frame.
- `(center)` Returns a position of the center of the frame. - `(center)` Returns a position of the center of the frame.
@ -68,7 +68,7 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
- `(rescale w h)` Rescales the canvas to target ratio of w and h, returns the rect. - `(rescale w h)` Rescales the canvas to target ratio of w and h, returns the rect.
- `(crop rect)` Crop canvas to rect. - `(crop rect)` Crop canvas to rect.
- `(clone a b)` - `(clone a b)`
- `(drag x y ~rect)` - `(drag ~rect)`
- `(theme variable ~el)` - `(theme variable ~el)`
- `(pixels rect fn q)` - `(pixels rect fn q)`
- `(saturation pixel ~q)` - `(saturation pixel ~q)`

View File

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

View File

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