Hi all, I hope this is the right place where to ask.

I've started looking in the python api oiio, and so far so good (with a bit of help from the sources) ,
on retrieving the metadata from the images .

I'm trying now to resize some images and converting them to jpgs ('thumbnails') All Jpgs images are resized correctly but not the others types (exr, dpx, etc..).

I've got a look at the resize of oiioutils , but I haven't managed to replicat it.
Any help is appreciated :)

Cheers.
L.

# ----  CODE ----

import os
from glob import glob
from pprint import pformat
import array

import OpenImageIO as oiio
plugin_path = "~/software/oiio/lib"

def thumbnail(image_path, output_path='/tmp):

    filename = os.path.basename(image_path).split('.')[0]

    spec = oiio.ImageSpec()
    imagein = oiio.ImageInput.create(image_path,plugin_path)

    if not imagein:
        return

    # Open the image and read it
    imagein.open(image_path, spec)
    imageb = spec.image_bytes(True)

    arr = array.array("B", "\0" * imageb)

    imagein.read_image(spec.format, arr)
    imagein.close()

    # create new spec for the thumbnail
    newspec = oiio.ImageSpec(spec)

    # cleanup the metadata
    newspec.extra_attribs.clear()

    # -> resize of the image
    newspec.width = 320
    newspec.height = 240
    newspec.full_x = newspec.x;
    newspec.full_y = newspec.y;
    newspec.full_width = newspec.width;
    newspec.full_height = newspec.height;

    output_file = os.path.join(output_path,'{0}.jpg'.format(filename))
    imageout = oiio.ImageOutput.create(output_file,plugin_path)
    imageout.open(output_file,newspec,oiio.ImageOutputOpenMode.Create)

    thumbnail = imageout.write_image(newspec.format, arr)

    # If succesful returns the thumbnail path
    if thumbnail:
        return output_file
    else:
        return None



paths = glob("~/src/oiio-images/*")
for path in paths:
    thumb = thumbnail(path)
    if thumb:
        print thumb

_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to