Using PIL in a method of a content type

3 messages Options
Embed this post
Permalink
Jan Pokorny () Using PIL in a method of a content type
Reply Threaded More More options
Print post
Permalink
Hello,

I have a custum content type "SightFolder" with a field "img" of  
"image" type. I would like to use some PIL transformations on the  
image saved in the image field, so I have added a method into the  
content type class. But all my attempts fail.

I import PIL as:

from PIL import Image

A field is defined as:

     ImageField(
         name='img',
         widget=ImageField._properties['widget'](
             label="Map",
         ),
         searchable=0,
         required=0,
         storage=AnnotationStorage(),
     ),

A method in the class is defined as:

     security.declarePublic('Rotate')
     def Rotate(self, img):
        out = img.rotate(45)
        return out

And I try to call it from a template as:

<span tal:replace="structure  
python:context.Rotate(context.img).tag()"></span>

But i generates the following error:

Module Products.PageTemplates.ZRPythonExpr, line 49, in __call__
    - __traceback_info__: context.Rotate(context.img).tag()
   Module PythonExpr, line 1, in <expression>
   Module Products.Sightseeing.SightFolder, line 142, in Rotate
AttributeError: rotate

Do you have any idea what is wrong? Is there any better way how to  
input an image from a field into a method?

Thanks a lot for any help in advance.

Jan




_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Zdych Lukáš () Re: Using PIL in a method of a content type
Reply Threaded More More options
Print post
Permalink
Hi Jan,

     it seems that your issue is that you are trying to call PIL's  
image object's method "Rotate" on Archetypes ImageField instance which  
can't work for sure .. but you should have a look at your current  
ATContentTypes package where these operations are already implemented  
somewhere in the module: Products.ATContentTypes/Products/
ATContentTypes/lib/imagetransform.py

     Btw: These operations would be accessable easily if you include  
ATContentTypes.content.image.Image class as one of your's class parent  
or you can use these transforms directly maybe .. but all that depends  
on what is your goal.

Kind Regards

Lukas

On Aug 11, 2009, at 11:12 PM, Jan Pokorný wrote:

> Hello,
>
> I have a custum content type "SightFolder" with a field "img" of  
> "image" type. I would like to use some PIL transformations on the  
> image saved in the image field, so I have added a method into the  
> content type class. But all my attempts fail.
>
> I import PIL as:
>
> from PIL import Image
>
> A field is defined as:
>
>    ImageField(
>        name='img',
>        widget=ImageField._properties['widget'](
>            label="Map",
>        ),
>        searchable=0,
>        required=0,
>        storage=AnnotationStorage(),
>    ),
>
> A method in the class is defined as:
>
>    security.declarePublic('Rotate')
>    def Rotate(self, img):
>       out = img.rotate(45)
>       return out
>
> And I try to call it from a template as:
>
> <span tal:replace="structure  
> python:context.Rotate(context.img).tag()"></span>
>
> But i generates the following error:
>
> Module Products.PageTemplates.ZRPythonExpr, line 49, in __call__
>   - __traceback_info__: context.Rotate(context.img).tag()
>  Module PythonExpr, line 1, in <expression>
>  Module Products.Sightseeing.SightFolder, line 142, in Rotate
> AttributeError: rotate
>
> Do you have any idea what is wrong? Is there any better way how to  
> input an image from a field into a method?
>
> Thanks a lot for any help in advance.
>
> Jan
>
>
>
>
> _______________________________________________
> Product-Developers mailing list
> [hidden email]
> http://lists.plone.org/mailman/listinfo/product-developers


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Espen Moe-Nilssen () Re: Using PIL in a method of a content type
Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
You could maybe call the "action" rotate "after the object is created.

There is also a product called "Image Cropping Field" (?) that might be worth taking a look at (=to see how pil is used here)

Not too much related, but take a look at Products.Imageeditor, a great product




Espen Moe-Nilssen
_______________________________________________

Author of Subskins III , build your own theme for Plone. Try it at:




Den 11. aug. 2009 kl. 23.32 skrev Zdych Lukáš:

Hi Jan,

    it seems that your issue is that you are trying to call PIL's image object's method "Rotate" on Archetypes ImageField instance which can't work for sure .. but you should have a look at your current ATContentTypes package where these operations are already implemented somewhere in the module: Products.ATContentTypes/Products/ATContentTypes/lib/imagetransform.py

    Btw: These operations would be accessable easily if you include ATContentTypes.content.image.Image class as one of your's class parent or you can use these transforms directly maybe .. but all that depends on what is your goal.

Kind Regards

Lukas

On Aug 11, 2009, at 11:12 PM, Jan Pokorný wrote:

Hello,

I have a custum content type "SightFolder" with a field "img" of "image" type. I would like to use some PIL transformations on the image saved in the image field, so I have added a method into the content type class. But all my attempts fail.

I import PIL as:

from PIL import Image

A field is defined as:

   ImageField(
       name='img',
       widget=ImageField._properties['widget'](
           label="Map",
       ),
       searchable=0,
       required=0,
       storage=AnnotationStorage(),
   ),

A method in the class is defined as:

   security.declarePublic('Rotate')
   def Rotate(self, img):
      out = img.rotate(45)
      return out

And I try to call it from a template as:

<span tal:replace="structure python:context.Rotate(context.img).tag()"></span>

But i generates the following error:

Module Products.PageTemplates.ZRPythonExpr, line 49, in __call__
  - __traceback_info__: context.Rotate(context.img).tag()
 Module PythonExpr, line 1, in <expression>
 Module Products.Sightseeing.SightFolder, line 142, in Rotate
AttributeError: rotate

Do you have any idea what is wrong? Is there any better way how to input an image from a field into a method?

Thanks a lot for any help in advance.

Jan




_______________________________________________
Product-Developers mailing list


_______________________________________________
Product-Developers mailing list


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers