crops get invalidated when the image title/description or other metadata is changed.
this should only happen if the image file itself gets changed.
<img tal:define="scales image_object/@@images;
img python:scales.scale('image', scale='large')"
tal:attributes="src img/url" />
it's important to mention that this only happens for scales.scale and not for the plone.app.imaging traverser:
test1.jpg/@@images/8689307d-f3e7-42c5-9134-f77f6e704cfe.jpeg will show the scaled image
test1.jpg/image_frontpage will still show the cropped image
did not yet investigate if this bug belongs to imagecropping or plone.scale or plone.app.imaging
until we don't want to change plone core modules, the only solution is to make a method which restores/resaves the scale on ObjectModifiedEvent
@jpgimenez this is going to bite us when we deprecate our image tile in favor of the standard tile (collective/collective.cover#81)
crops are also lost when image is copied.
i've done some experimental monkey-patching of plone.scales to avoid that, but needs cleanup and more testing. Feedback is welcome.
description="Patch plone.scales to create cropped images"
Several ugly things are happening down below. I'd love to see an adapter for plone.scales which queries for a factory how to create crops. What do you think about that?
from plone.app.imagecropping import PAI_STORAGE_KEY
from plone.app.imagecropping.interfaces import IImageCroppingUtils
from zope.annotation.interfaces import IAnnotations
from zope.component import getMultiAdapter
def patched_scale(self, factory=None, **parameters):
"""This is a really dirty hack to re-create blob files if a
cropping information was stored in object annotation.
info = self._old_scale(factory, **parameters)
# XXX: That's very nasty
if not factory.func_name == 'crop_factory' \
and (parameters.get('width') != info.get('width') or
parameters.get('height') != info.get('height')):
cropped = IAnnotations(self.context).get(PAI_STORAGE_KEY)
if not cropped:
utils = IImageCroppingUtils(self.context)
cropping_view = getMultiAdapter(
(self.context, self.context.REQUEST), name='crop-image')
for fieldname in utils.image_field_names():
for image_name, box in cropped.items():
scale = image_name.split('_').pop()
cropping_view._crop(fieldname, scale, box)
any news on this issue?
just stumbled over a discussion on plone.scale (plone/plone.scale#3) which is related to this
@tomgross and i fixed this ticket in #38
for dexterity, this currently means to implement another interface.
@joka as dexterity pro: are you ok with that? personally i'd love to see that we can find a way to make dexterity content that implement IImageCropping also implement IImageCroppingScale.
if we can't find a way to make that happen, we should think about moving this interface out of the browser package to plone.app.imagecropping.interfaces and add some documentation to the readme
@saily reading through the comments here i see you mentioned copying an image too. i did not test that yet. would be great to get your feedback if this fixes your issues too.
Let's write a test to check that, should be easy to implement. i'll try to find some time for that... anyway, thanks for fixing
Hi @frisi, unfortunately this does not fix the copying issue. I've opened a pull #40 which could be a nice base to fix that. i'm closing this right now, because the main problem seems to be fixed in #38