get final image width and height from the selection area
parent
1ba0215ecd
commit
2c4e832c16
7
index.js
7
index.js
|
|
@ -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 () {
|
||||
|
|
|
|||
2
psapi.js
2
psapi.js
|
|
@ -829,7 +829,7 @@ async function createClippingMaskExe () {
|
|||
|
||||
async function checkIfSelectionAreaIsActive()
|
||||
{
|
||||
let isSelectionAreaValid = getSelectionInfoExe()
|
||||
let isSelectionAreaValid = await getSelectionInfoExe()
|
||||
return isSelectionAreaValid
|
||||
}
|
||||
async function saveUniqueDocumentIdExe (new_id) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
Loading…
Reference in New Issue