ome / omero-figure

An OMERO.web app for creating Figures from images in OMERO
http://figure.openmicroscopy.org
GNU Affero General Public License v3.0
15 stars 30 forks source link

Review scale_to_export_dpi() in export script #424

Open will-moore opened 3 years ago

will-moore commented 3 years ago

See https://github.com/ome/omero-figure/pull/409

def scale_to_export_dpi(pixels):
    return pixels * 300 // 72

Sometimes the output of scale_to_export_dpi() is rounded up, or down:

        stroke_width = scale_to_export_dpi(shape.get('strokeWidth', 2))
        buffer = int(ceil(stroke_width))
        ...
        width = int(round(stroke_width))

but mostly it is cast directly to int. Currently it can return an int or float depending on the input type, but the number is always equal to an integer because it uses integer division. So, check if we need to use ceil() or round() (from Python 2 days) or if we can just return an int. Then, we could cast the input to float(pixels).

Sometimes we rely on it returning an int, e.g. this is used for scalebars:

        width = scale_to_export_dpi(width)
        for l in range(width):
            draw.line([(x, y), (x2, y2)], fill=rgb)

cc @emilroz