Hi Ale,

if you have time, the attached script could be used for a "generic"
demo: it just converts an image to grayscale; should work with any
image format that is supported by ImageMagick (i.e., basically *any*
image format).

Note: for running on the cloud, the script needs a VM with package
"imagemagick" installed (vanilla Ubuntu 16.04 does *not* have it).

Thanks,
R

-- 
You received this message because you are subscribed to the Google Groups 
"gc3pie-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to gc3pie-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/gc3pie-dev/CAJGE3zVhc3a_LJJs0zgxc0%2BjnVhkROLWwF37aTSp%2Bx4DdELSMg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
#! /usr/bin/env python

import os
from os.path import abspath, basename
import sys

from gc3libs import Application
from gc3libs.cmdline import SessionBasedScript
from gc3libs.quantity import GB


if __name__ == '__main__':
    from grayscaler import GrayscaleScript
    GrayscaleScript().run()


class GrayscaleScript(SessionBasedScript):
    """
    Convert images to grayscale.
    """
    def __init__(self):
        super(GrayscaleScript, self).__init__(version='1.0')
    def new_tasks(self, extra):
        # since `self.params.args` is already a list of file names,
        # just iterate over it to build the list of apps to run...
        apps_to_run = []
        for input_file in self.params.args:
            input_file = abspath(input_file)
            apps_to_run.append(GrayscaleApp(input_file, **extra))
        return apps_to_run


# alternatively, you could use
# `from grayscale_app import GrayscaleApp` above
class GrayscaleApp(Application):
    """Convert a single image file to grayscale."""
    def __init__(self, img, **extra):
        inp = basename(img)
        out = "gray-" + inp
        Application.__init__(
            self,
            arguments=[
                "convert", inp, "-colorspace", "gray", out],
            inputs=[img],
            outputs=[out],
            stdout="stdout.txt",
            stderr="stderr.txt",
            **extra)

Reply via email to