enrecipes/app/workers/ImageProcessor.worker.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-11-02 11:36:53 +00:00
require("tns-core-modules/globals")
2020-11-10 18:28:48 +00:00
import { ImageSource } from "@nativescript/core"
var ImageCropper = require("nativescript-imagecropper").ImageCropper
2020-11-02 11:36:53 +00:00
global.onmessage = function({ data }) {
2020-11-10 18:28:48 +00:00
console.log(data)
2020-11-02 11:36:53 +00:00
let imgSavedToPath = data.imgSavedToPath
2020-11-10 18:28:48 +00:00
let imgPath = data.imgPath
let screenWidth = data.screenWidth
let toolbarTextColor = data.toolbarTextColor
let toolbarColor = data.toolbarColor
ImageSource.fromFile(imgPath).then((image) => {
ImageCropper.prototype
.show(
image,
{
width: screenWidth,
height: screenWidth,
// compressionQuality: 75,
},
{
hideBottomControls: true,
toolbarTitle: "Crop photo",
statusBarColor: "#ff5200",
toolbarTextColor,
toolbarColor,
cropFrameColor: "#ff5200",
}
)
.then((cropped) => {
if (cropped.image.saveToFile(imgSavedToPath, "jpg", 75))
global.postMessage("savedToFile")
})
2020-11-02 11:36:53 +00:00
})
}
2020-11-10 18:28:48 +00:00
// global.onmessage = function({ data }) {
// let imgSavedToPath = data.imgSavedToPath
// let imgAsset = new ImageAsset(data.imgFile)
// imgAsset.options = {
// width: 1200,
// height: 1200,
// keepAspectRatio: true,
// }
// ImageSource.fromAsset(imgAsset).then((imgData) => {
// if (imgData.saveToFile(imgSavedToPath, "jpg", 75)) {
// global.postMessage("savedToFile")
// }
// })
// }