Question

Attributes available on a Dexterity Content Type with Image Field:

>>> app.Plone.test.image.
app.Plone.test.image.__class__(         app.Plone.test.image.__provides__(      app.Plone.test.image._height            app.Plone.test.image._p_state
app.Plone.test.image.__delattr__(       app.Plone.test.image.__reduce__(        app.Plone.test.image._p_activate(       app.Plone.test.image._setData(
app.Plone.test.image.__dict__           app.Plone.test.image.__reduce_ex__(     app.Plone.test.image._p_changed         app.Plone.test.image._width
app.Plone.test.image.__doc__            app.Plone.test.image.__repr__(          app.Plone.test.image._p_deactivate(     app.Plone.test.image.contentType
app.Plone.test.image.__format__(        app.Plone.test.image.__setattr__(       app.Plone.test.image._p_delattr(        app.Plone.test.image.data
app.Plone.test.image.__getattribute__(  app.Plone.test.image.__setstate__(      app.Plone.test.image._p_estimated_size  app.Plone.test.image.filename
app.Plone.test.image.__getstate__(      app.Plone.test.image.__sizeof__(        app.Plone.test.image._p_getattr(        app.Plone.test.image.getFirstBytes(
app.Plone.test.image.__hash__(          app.Plone.test.image.__str__(           app.Plone.test.image._p_invalidate(     app.Plone.test.image.getImageSize(
app.Plone.test.image.__implemented__(   app.Plone.test.image.__subclasshook__(  app.Plone.test.image._p_jar             app.Plone.test.image.getSize(
app.Plone.test.image.__init__(          app.Plone.test.image.__weakref__        app.Plone.test.image._p_mtime           app.Plone.test.image.open(
app.Plone.test.image.__module__         app.Plone.test.image._blob              app.Plone.test.image._p_oid             app.Plone.test.image.openDetached(
app.Plone.test.image.__new__(           app.Plone.test.image._data              app.Plone.test.image._p_serial          app.Plone.test.image.size
app.Plone.test.image.__providedBy__(    app.Plone.test.image._getData(          app.Plone.test.image._p_setattr(

I would expect a method getImage or getImageURL method to be present… so much so that I found myself working around its absence via the following:

def get_image(self):
    return "data:%s;base64,%s" % (self.context.image.contentType,
        base64.encodestring(self.context.image.data))

And:

<img tal:attributes="src view/get_image" />

Which works, but is not ideal in many (hopefully obvious) ways. Now, the default view of this type provides the desired functionality via a widget resource:

view/++widget++form.widgets.image/@@download/the-image.png

But I don't have access to it (AFAICT) because I've customized the default view of this type. Should there be a getImage method? Or am I missing some other obvious approach.

Was it helpful?

Solution

Have you tried it in plone.app.imagescales-way

<img tal:replace="structure context/@@images/shortnameofmyfield/thumb" />

OTHER TIPS

I resolved a similar issue like this:

selected_image.restrictedTraverse("@@images").scale('image', width=None, height=None).index_html() 

This returns the image in its original size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top