0

io image-formatter API options / docs
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

io image-formatter API options / docs

by dearmash on Fri Nov 27, 2020 2:59 am

I've been looking into the details of the the image converter service courtesy of the pyportal examples

https://github.com/adafruit/Adafruit_Ci ... al.py#L100

I can't find any documentation for that API beyond what is given in that example, and random parameters don't seem to do anything.

One thing I've been running in to is converting images that have transparent backgrounds, it seems like the converter service defaults to making them white. It would be nice to specify a background color in those cases, black for my specific case, but hex would be extremely helpful.

*Edit: Also it seems like https://io.adafruit.com/{username}/monitor doesn't apply to this API's throttling / usage. I've been rate limited a few times here and there, so knowing what those limits are as well would be useful.

dearmash
 
Posts: 45
Joined: Mon Nov 28, 2011 4:20 pm

Re: io image-formatter API options / docs

by brubell on Mon Nov 30, 2020 11:31 am

I can't find any documentation for that API beyond what is given in that example, and random parameters don't seem to do anything.

One thing I've been running in to is converting images that have transparent backgrounds, it seems like the converter service defaults to making them white. It would be nice to specify a background color in those cases, black for my specific case, but hex would be extremely helpful.


There's no documentation as this service isn't an official Adafruit IO service (io.adafruit.com/services), it's just a helper script we created for a few of our libraries and we host it on Adafruit IO. The normal rate limit of 30 data points per minute, 60 per minute for plus subscribers, still applies.

brubell
 
Posts: 1377
Joined: Fri Jul 17, 2015 10:33 pm

Re: io image-formatter API options / docs

by dearmash on Mon Nov 30, 2020 10:37 pm

Because I feel bad making feature requests for what is essentially a free helper meant only for your libraries...

If the next person in line is so inclined, here's where I ended up with a result that's hosted on the web and did at least as much as I needed, as close to the existing image-formatter API provided by adafruit. From what I can tell, the usage from my personal account should be pennies per month if it even does go over the free tier usage.

So "good enough for me", ymmv.

These directions are pretty plug and play for getting a python "web function" up and running
https://github.com/GoogleCloudPlatform/ ... d_run_http

requirements.txt
Code: Select all | TOGGLE FULL SIZE
Pillow
requests


main.py
Code: Select all | TOGGLE FULL SIZE
from urllib.parse import urlparse, parse_qs
from PIL import Image
import requests
from io import BytesIO
from flask import send_file

def formatimage(request):
    request_args = request.args

    url = request.args['url'] if request.args and 'url' in request.args else None
    width = request.args['width'] if request.args and 'width' in request.args else None
    height = request.args['height'] if request.args and 'height' in request.args else None
    output = request.args['output'] if request.args and 'output' in request.args else None

    width = int(width)
    height = int(height)

    img = Image.open(BytesIO(requests.get(url).content))
    img = img.resize((width, height))

    img_bytes = BytesIO()
    img.save(img_bytes, format='BMP')
    img_bytes.seek(0)

    return send_file(img_bytes, mimetype='image/bmp')

dearmash
 
Posts: 45
Joined: Mon Nov 28, 2011 4:20 pm

Please be positive and constructive with your questions and comments.