Hi all,

I would like to share my thoughts on what I am currently working on with the 
hope to get  some input to have it done 100% Ofbiz style. Maybe this feature 
could be interesting for the project:

Goal: resize uploaded images to predefined scales (Content Management)
File representation:

Original ../ofbiz/runtime/uploads/11111111/10001.jpeg
Small ../ofbiz/runtime/uploads/11111111/SMALL/10001.jpeg
...

Reason: improve load time of page by reducing image size

How to:

Config: 
- Define scales
- Turn feature on & off.

Create Service "createScalesFromUploadedImage" and add code to do the resize 
job.

Insert service in:
.. applications\content\servicedef 

    <service name="createContentFromUploadedFile" engine="group" 
transaction-timeout="300">
        <description>Accepts file upload, creates DataResource and Content 
records.</description>
        <!-- uses createContent internally; additonal permission(s) not 
necessary -->
        <group>
            <invoke name="createDataResource" parameters="preserve" 
result-to-context="true"/>
            <invoke name="attachUploadToDataResource" parameters="preserve" 
result-to-context="true"/>
            <invoke name="createContentFromDataResource" parameters="preserve" 
result-to-context="true"/>
           <invoke name="createScalesFromUploadedImage"/>
        </group>
    </service>
    <service name="updateContentAndUploadedFile" engine="group" 
transaction-timeout="300">
        <description>Accepts file upload, updates DataResource and Content 
records.</description>
        <group>
            <invoke name="updateDataResource" parameters="preserve" 
result-to-context="true"/>
            <invoke name="attachUploadToDataResource" parameters="preserve" 
result-to-context="true"/>
            <invoke name="updateContent" parameters="preserve" 
result-to-context="true"/>
                        <invoke name="createScalesFromUploadedImage"/>
        </group>
    </service>


This works already using CMS. Creating an image by using "create content" seems 
to call different methods to upload the image. I still have to check why.

Adding an "ImageWorker" class to access the scaled images with methods like " 
getImageScaleFromDataResource, getImageScaleFromContent ". I do not thing they 
should be added to the database as dataresources as they are just another 
representation of the original image. If the image scale is not available it 
will be created on fly. If the original image is there, there is no reason to 
result in 404. Service to scale the image is called when 
- uploading, 
- updating, 
- retrieved and file is not available.

Workflow to stream the image:

Call stream like: "stream?contentId=10001?scale=small"

"stream" --> DataEvents.serveObjectData

Add:
String imageScale = (String) httpParams.get("scale");
.
.
resourceData = ImageWorker. getImageScaleFromDataResource (dataResource, https, 
webSiteId, locale, contextRoot, scale, false);

Then the image gets streamed.

I would appreciate any thoughts.

Ingo






 

Reply via email to