Skip to content

Instantly share code, notes, and snippets.

@nolivo
Last active May 31, 2022 19:04
Show Gist options
  • Save nolivo/3f4ee4875500e106074730010c3534a1 to your computer and use it in GitHub Desktop.
Save nolivo/3f4ee4875500e106074730010c3534a1 to your computer and use it in GitHub Desktop.
mapSizer.js A script that resizes an image and page to specific dimensions, centers the image on the page and puts it on the map layer.
//usage - !mapSizer imageWidthInPixels imageHeightInPixels
on("ready",function(){
on("chat:message",function(msg){
if(msg.type=="api" && msg.content.indexOf("!mapSizer")==0){
var args = msg.content.split(" ");
var mapWidth = Number(args[1]);
var mapHeight = Number(args[2]);
var selected = msg.selected;
if(selected===undefined){
sendChat("API","Please select a graphic");
return;
}
if(isNaN(mapWidth)||isNaN(mapHeight)){
sendChat("API","Please enter a valid number for width & height");
return;
}
var map = getObj("graphic",selected[0]._id);
var page = getObj("page",map.get("pageid"));
page.set({
width:mapWidth/70,
height:mapHeight/70
});
map.set({
width:mapWidth,
height:mapHeight,
top:mapHeight/2,
left:mapWidth/2,
layer:"map"
});
}
});
});
@emeljaycode
Copy link

This is great. I adjusted using your YT updates. I new to this coding thing so going to try to update that to any sizer instead of just maps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment