get final image width and height from the selection area

pull/53/head
Abdullah Alfaraj 2023-01-11 00:39:39 +03:00
parent 1ba0215ecd
commit 2c4e832c16
3 changed files with 51 additions and 1 deletions

View File

@ -16,6 +16,13 @@ const dialog_box = require('./dialog_box')
const html_manip = require('./html_manip')
const export_png = require('./export_png')
const viewer = require('./viewer')
const selection = require('./selection')
const eventHandler = (event, descriptor) => {
console.log("event got triggered!")
console.log(event, descriptor)}
require("photoshop").action.addNotificationListener(['all'], eventHandler);
async function getUniqueDocumentId () {

View File

@ -829,7 +829,7 @@ async function createClippingMaskExe () {
async function checkIfSelectionAreaIsActive()
{
let isSelectionAreaValid = getSelectionInfoExe()
let isSelectionAreaValid = await getSelectionInfoExe()
return isSelectionAreaValid
}
async function saveUniqueDocumentIdExe (new_id) {

43
selection.js Normal file
View File

@ -0,0 +1,43 @@
function finalWidthHeight(selectionWidth,selectionHeight,minWidth,minHeight){
// const minWidth = 512
// const minHeight = 512
// const selectionWidth = 256
// const selectionHeight = 1000
let finalWidth = 0
let finalHeight = 0
if(selectionWidth <= selectionHeight){
//do operation on the smaller dimension
const scaleRatio = selectionWidth / minWidth
finalWidth = minWidth
finalHeight = selectionHeight / scaleRatio
}else{
const scaleRatio = selectionHeight / minHeight
finalHeight = minHeight
finalWidth = selectionWidth / scaleRatio
}
return [finalWidth,finalHeight]
}
async function selectionToFinalWidthHeight(){
const {getSelectionInfoExe} = require('./psapi')
try{
const selectionInfo = await getSelectionInfoExe()
const [finalWidth,finalHeight] = finalWidthHeight(selectionInfo.width,selectionInfo.height,512,512)
return [parseInt(finalWidth),parseInt(finalHeight)]
}catch(e){
console.warn("you need a rectangular selection",e)
}
}
module.exports = {
finalWidthHeight,
selectionToFinalWidthHeight
}