Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Script] ArtResizer - Solution to automatically resize art when dropped on the map

When you have acquired loads of Art Packs on roll20 there is one thing that hinders the usage of that art. If you drag-and-drop an asset into the VTT, the size is not right (most of the time) and you have to manually resize the image. Manual resizing is a chore during game preparation and a definite disaster when you GM groups that require regurar improvisation - you can't just drop some roofs and trees on a background. So i decided to write a script to auto-size art. In the API sandbox the script can provide an eventhandler for the the 'add:graphic' event. In this eventhandler the graphic can be resized. However, the script has no access to the image content, image size or the name of the image in the sidebar. The only available data specific to the asset is the imgsrc attribute. Many art packs allow the pack to be downloaded as a zip file and there is a folder on my computer with dozens of them. Each asset in these zip-files has a name that starts with a number, a number that can be found within the url of imgsrc. Artists provide hints in the assets name as to what's the right grid size (in the sidebar these these often are outside the sidebar - so you can't see them); if there is no hint in the file name, most artist adhere to the 140x140 pixels per "square" rule or at least are consistent in the pixel to grid ratio within a pack.&nbsp; If there is some way to link these in a api script that would mean ... profit!&nbsp; This solution preprocesses the assets of the downloaded packs and stores the metadata required for resizing in an apiscript. The solution consists of three scripts.&nbsp; 1) a javascript script ArtSizer_template.js taht is a template with all the code but without the metadata.&nbsp; 2) a python script that determines the grid sizes of all bought art packs and injects these into the javascript template.&nbsp; 3) a (to-be generated) javascript script ArtSizer.js that can be uploaded in the API console. This one is created by the python script (ie you need to generate this one yourself). The generated script is about 250kb in my case and the Roll20 javascript editor accepts it without issue. And now when i drop in assets... Backgrounds are 30x30 backgrounds instead of 3x3 stamps. Trees grow where you plant them. It feels like magic!&nbsp; Feel free to adapt and reuse. Enjoy! Template can be found here: <a href="https://gist.github.com/MartijnSanders/d4f11400a27aaddd4c6d74fac4a8d8ad" rel="nofollow">https://gist.github.com/MartijnSanders/d4f11400a27aaddd4c6d74fac4a8d8ad</a> Python script can be found here: <a href="https://gist.github.com/MartijnSanders/573ecb9e41524faa5a88d1bf819034fe" rel="nofollow">https://gist.github.com/MartijnSanders/573ecb9e41524faa5a88d1bf819034fe</a> Note 1: As API sandboxs are docker containers nowadays i'm not afraid that this amount of data and processing in scripts impacts other games. The overhead of dockers itself is like 1000x this data. If my assumption is not correct... let me know.&nbsp; Note 2: I decided against storing the data in handouts... the cost of this solution is a single load on sandbox startup and a little memory. I consider this way less overhead and work than storing and accessing the data in handouts. Note 3: In the meantime support has been added for hex assets, like <a href="https://marketplace.roll20.net/browse/set/2368/hex-march-vol-1-world-map-builder" rel="nofollow">https://marketplace.roll20.net/browse/set/2368/hex-march-vol-1-world-map-builder</a> Note 4: This only works for Art Packs that can be downloaded and not for art that comes in the form of add-ons.
1610914218
Andreas J.
Forum Champion
Sheet Author
Translator
ScaleOnAdd is a slightly related API&nbsp; by Aaron, dunno if it contains any ideas you might want to incorporate to your more comprehensive API.
1610919674

Edited 1610923705
In terms of functionally, ScaleOnAdd has a command to set the dimensions that will be applied. And a toggle command that when on, effects that these dimensions will be applied to all added images. This is generic, but requires manual data entry during map-design.&nbsp; I might adopt the 'collect during&nbsp; on:add &nbsp;event' and 'change during on:change &nbsp;event'&nbsp; method, ArtResizer just waits 200 milliseconds.