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

Changing the 'imgsrc' using the API

April 04 (11 years ago)

Edited April 04 (11 years ago)
I have been playing around with the API and manipulating the 'imgsrc' on various tokens.

I have encountered a big problem. Some of my tokens I can change and then change back, others I cannot.

I can store the existing image in a variable but then when I use the API to reverse the change i get the following error message:

"ERROR: You cannot set the imgsrc or avatar of an object unless you use an image that is in your Roll20 Library. See the API documentation for more info."

All of the tokens that I use are from my 'library' so why do i receive this error? I have noticed that a lot of the tokens in my library still have the \marketplace folder in the URL. How do i fix this???

OMG...

I just copied one of my tokens and pasted the image and then uploaded it back into my library. The URL has changed and it now works...

Please don't tell me that I have to do this for most of the tokens in my library to get them to work with the API???

It will take me forever, sad face :(

April 04 (11 years ago)
No, it's not that bad. This part of the wiki (the third point) explains how there are different versions of the images and you need to use a specific one. So you need to replace the "something.png" part of your imgsrc with "thumb.png", even if it's the original image that was on the token.

One way to do it would be using lastIndexOf to find the last period (.) and the last slash (/), or you could directly replace "med.png" and whatever other possibilities there are - I can't remember the other but I think there may have only been 2.
April 04 (11 years ago)

Edited April 04 (11 years ago)

Rendelle F. said:

No, it's not that bad. This part of the wiki (the third point) explains how there are different versions of the images and you need to use a specific one. So you need to replace the "something.png" part of your imgsrc with "thumb.png", even if it's the original image that was on the token.

One way to do it would be using lastIndexOf to find the last period (.) and the last slash (/), or you could directly replace "med.png" and whatever other possibilities there are - I can't remember the other but I think there may have only been 2.


This is not my problem...

Many of the images that are in my library still have the '/marketplace' folder in the URL. I cannot simply replace the '/marketplace' folder with the '/images' folder to make it work. I have to re-upload the image back into my library so that it has the correct URL.

I have tried manipulating the original URL in the API with no success.

Here is an example:

https://s3.amazonaws.com/files.d20.io/marketplace/16914/EKFCT3Ik-5C32yu5K0RxKQ/thumb.png?1367514091

https://s3.amazonaws.com/files.d20.io/images/3617830/4K4GbzjTBo2g2V1kRb2eQA/thumb.png?1396646193

The first link is the original URL of the token image in my library (as you can see it has the '/marketplace' folder in the URL and will not work with the API)

The second link is the same token but it has been re-uploaded into my library and it will now work with the API.

If somebody can help me make the first link work with the API by being able to manipulate the URL inside the API then I am all ears, because it will take me a very long time to go through all of the images in my library and work out which ones have the incorrect URL to be used in the API and then re-upload them. It would be no exaggeration to say that I have over 700 token images.


April 06 (11 years ago)
I guess I missed the last line of your post - sorry for that.

Unfortunately, as the first point on the wiki explicitly states that marketplace images can't be accessed this way, I think you're out of luck. I could be wrong, but I can't think of any reason they would need, for their own code, the image to exist in the format of the first URL, and so I can't imagine that they would have thought to create that secondary method of linking to it. I also can't see them lifting this restriction, since otherwise it would allow for someone to create a script that makes use of marketplace images, then distribute that script to others who may not have purchased those images. You could try putting a suggestion in about a new URL being created at the time of purchase. For this reason, it would make sense to have it.

I do hope I'm wrong, though!
Thank you for your response Rendelle. It is starting to look like an oversight by the developers.

The URL should be without the '/marketplace' extension after the tokens have been purchased and placed into the library. I guess I will have to go through each of them manually to determine which ones need to be re-uploaded so they have the correct URL that will be compatible with the API. Unfortunately It is a massive task and it will take me a considerable amount of time.

Right now I am a little frustrated with the limitations placed on the files that can be used by the API for 'imgsrc'.

I have 'mentor' status so I am able to use Kristin's template tokens for spells. The only way that I can use these images via the API is by saving the images and then re-uploading them into my library. There is a problem... A huge loss of quality occurs with the image and it becomes 'blurry'. I have tried right clicking and copying the images as well as copying the URL and pasting the URL into my browser to download the image directly from the source. No luck. The image is always blurred when it is uploaded into my library. How do I get around this?
Okay... I found a work around to obtain he full resolution of the images. I had to select the star on the tokens in the marketplace and then copy the URL from my library to get the maximum size of the image which I then re-uploaded back into my library. Voila!

A long winded process in order to use them with the API but at least it works :)