Just glancing at your Python script, it looks like you are reading the image, 
doctoring the spec to have the resolution you want, then writing the same image 
out with the new spec.  I'm afraid that is not going to resize it.  When you 
output an image, the spec you pass just tells OIIO the dimensions of the 
buffer, it doesn't force a resize.  What you need to do is read the image in, 
*do the math and produce a new array of pixels you want at the new size*, then 
write that new buffer using the new spec whose resolution matches the buffer.  
I hope that description makes some sense.

How badly do you need to do this in Python?  If you just want a fast path to 
resizing images and converting to JPEG, try using the 'oiiotool' utility from 
the command line.  You'd want something like:

        oiiotool oldfile.exr --resize 320x240 -o newfile.jpg

As an aside, it's easy for me to believe that the Python bindings either have 
bugs, or have drifted a bit from the C++ implementation lately.  It surely 
needs some love that it hasn't had for a while. That may have nothing to do 
with the problem you are having, if I understand correctly.  But I bring it up 
because if you are really intent on doing the resize in Python, we probably 
need to do some work to expose the ImageBufAlgo::resize in Python, and possibly 
patch up a couple other things along the way.

        -- lg



On Apr 15, 2012, at 12:48 PM, lorenzo angeli wrote:

> 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

--
Larry Gritz
[email protected]


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

Reply via email to