You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Bryce Ewing <br...@smx.co.nz> on 2008/07/07 04:44:20 UTC

Multi-pass rendering

Hi,

I am wondering if there is any way to do a two (or more) pass rendering 
for content, i.e.

Single rendering:
    GET /alpha/beta.html
    resource /alpha/beta (which has sling:resourceType = "test")
    uses /apps/test/html.ftl to render the node beta -> beta.html

Multi rendering:
    GET /alpha/beta.html
    ... (not sure about this part) ...
    uses two scripts to render the content, one which takes it from 
source to intermediary then a second one to render to html

Maybe something like this would work?
    GET /alpha/beta.xml.html
    resource /alpha/beta.xml (which has sling:resourceType = "test2")
    uses /apps/test2/html.ftl to render the node beta.xml -> beta.xml.html
    resource /alpha/beta (which has sling:resourceType = "test1")
    uses /apps/test1/html.ftl to render the node beta -> beta.xml

A specific example of where this would come in handy would be:
    /alpha/beta -> /alpha/beta.xml -> /alpha/beta.xml.pdf (where the xml 
step is fop)

Maybe I am going down a completely wrong track with the multi-pass 
rendering so more specifically how would I render a pdf (via first 
creating fop)?

Cheers
Bryce

Re: Multi-pass rendering

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Jul 8, 2008 at 11:26 AM, Bryce Ewing <br...@smx.co.nz> wrote:

> ...for this one it would be good to be able to
> change the resource type between stages as well (maybe using ordered child
> nodes to store the information rather than a multivalue property) e.g.
>   {
>       "pdf.pipeline" : {
>           "generatefo": {
>               "outputFormat":"xml",
>               "resourceType":"bar"
>           },
>           "serialize": {
>               "outputFormat":"pdf"
>           }
>       }
>   }
> would run /apps/foo/xml.ftl then /apps/bar/pdf.ftl (for example).

That looks nice but this is also easy to express with a pipeline
scripting language, for example:

  generate (outputFormat: xml, resourceType: bar)
  serialize (outputFormat: pdf)

And I think it's more inline with what we're doing currently -
pipelines would then be just another script engine, which IMHO makes
sense: like a script, a pipeline taks the current Resource as input,
processes it according to a specific execution language, and writes
the result to the client.

But the killer advantage of scripts vs. node structures, when it comes
to programming (and pipelines *are* programming in my opinion) is the
ease of editing: with scripts you need no tools other than curl or a
WebDAV client to work with Sling, whereas node types are much more
painful to edit, even with a good JCR explorer.

> ...More wondering what the thoughts are on the general idea of using the nodes
> in jcr rather than a scripting language for this purpose?...

Let's see what others think!

-Bertrand

Re: Multi-pass rendering

Posted by Carsten Ziegeler <cz...@apache.org>.
Bryce Ewing wrote:
> When you said a pipeline it got me thinking about why something like 
> this would necessarily be best implemented as a script (also thinking 
> the same in regards to the image processing).  What I was thinking is 
> would it be better to implement this as nodes in jcr rather than a 
> custom script language e.g. (using json notation):
>    in /apps/foo {
>        "pdf.pipeline" : {
>           "stages": ["xml", "pdf"]
>        }
>    }
> would allow for running scripts /apps/foo/xml.ftl then /apps/foo/pdf.ftl 
> (for example), was thinking for this one it would be good to be able to 
> change the resource type between stages as well (maybe using ordered 
> child nodes to store the information rather than a multivalue property) 
> e.g.
>    {
>        "pdf.pipeline" : {
>            "generatefo": {
>                "outputFormat":"xml",
>                "resourceType":"bar"
>            },
>            "serialize": {
>                "outputFormat":"pdf"
>            }
>        }
>    }
> would run /apps/foo/xml.ftl then /apps/bar/pdf.ftl (for example).
> OR use scripts specifically
>    {
>        "pdf.pipeline" : {
>           "jcr:path:stages": ["/apps/foo/test.ftl", "/apps/bar/test2.ftl"]
>        }
>    }
> would allow for running the mentioned scripts.
> 
> More wondering what the thoughts are on the general idea of using the 
> nodes in jcr rather than a scripting language for this purpose?
> 
I actually dont know what the best approach is, so I'm just daydreaming 
a little bit....
I think a pipeline is a good way of performing the rendering in several 
steps. Now, the important part here is what the contract between the 
components in the pipeline is? Having the background of Cocoon I think 
an XML based
approached is a very good way as this gives a nice but flexible contract
between the pipeline components. I'm not sure if using scripts for the 
intermediate format would be my choice - i'm not saying that it is 
wrong, but I've written so many SAX based components over the last years 
that I would prefer this :)

So this is the technical ground for implementing a pipeline based 
concept - the other question is how to configure this wrt Sling. This 
could be a "pipeline" script (perhaps using json format or xml) which 
specifies the pipeline components that should be used. The components 
itself are Java components managed by OSGi.

Now, the whole pipeline implementation could come from the Cocoon Corona 
approach, so we would just need to provide the glue stuff for Sling.

Just my 2 cents

Carsten
-- 
Carsten Ziegeler
cziegeler@apache.org

Re: Multi-pass rendering

Posted by Bryce Ewing <br...@smx.co.nz>.
Hi Bertrand,

Pipelines sound like an ideal way of doing this, some comments below.

Bertrand Delacretaz wrote:
> Hi Bryce,
>
> On Mon, Jul 7, 2008 at 4:44 AM, Bryce Ewing <br...@smx.co.nz> wrote:
>   
>> ...I am wondering if there is any way to do a two (or more) pass rendering for
>> content,...
>>     
>
> I don't think this is currently possible without using workarounds.
>
>   
>> ...Multi rendering:
>>   GET /alpha/beta.html
>>   ... (not sure about this part) ...
>>   uses two scripts to render the content, one which takes it from source to
>> intermediary then a second one to render to html...
>>     
>
> What could work (as a temporary solution) might be for your script to
> make another http request that generates the first format, captures
> that output and provides it to the module (FOP in your example) that
> generates the second format.
>
>   
Thankfully I am not requiring this right now, so would be better to work 
on a more long term solution than just a work around.
>> ... Maybe something like this would work?
>>   GET /alpha/beta.xml.html
>>   resource /alpha/beta.xml (which has sling:resourceType = "test2")
>>   uses /apps/test2/html.ftl to render the node beta.xml -> beta.xml.html
>>   resource /alpha/beta (which has sling:resourceType = "test1")
>>   uses /apps/test1/html.ftl to render the node beta -> beta.xml...
>>     
>
> Do you mean encoding in the URL the steps used to generate the
> response? I don't like that too much.
>   
I agree, was mainly using that as an example, I would rather not have to 
know when entering a url that it was first transformed into xml then 
into pdf.
> I'd prefer implementing real pipelines, using a specific *script*
> extension to control a simple pipeline engine:
>
> GET /foo/bar.pdf (resource type foo)
> -> handled by /apps/foo/pdf.pipeline script
>
> Where pdf.pipeline might be a simple pipeline control language:
>
> transform /apps/foo/xslt/xslfo.xsl
> serialize org.apache.sling.serializers.fop
>   options outputFormat=pdf
>   
When you said a pipeline it got me thinking about why something like 
this would necessarily be best implemented as a script (also thinking 
the same in regards to the image processing).  What I was thinking is 
would it be better to implement this as nodes in jcr rather than a 
custom script language e.g. (using json notation):
    in /apps/foo {
        "pdf.pipeline" : {
           "stages": ["xml", "pdf"]
        }
    }
would allow for running scripts /apps/foo/xml.ftl then /apps/foo/pdf.ftl 
(for example), was thinking for this one it would be good to be able to 
change the resource type between stages as well (maybe using ordered 
child nodes to store the information rather than a multivalue property) e.g.
    {
        "pdf.pipeline" : {
            "generatefo": {
                "outputFormat":"xml",
                "resourceType":"bar"
            },
            "serialize": {
                "outputFormat":"pdf"
            }
        }
    }
would run /apps/foo/xml.ftl then /apps/bar/pdf.ftl (for example).
OR use scripts specifically
    {
        "pdf.pipeline" : {
           "jcr:path:stages": ["/apps/foo/test.ftl", "/apps/bar/test2.ftl"]
        }
    }
would allow for running the mentioned scripts.

More wondering what the thoughts are on the general idea of using the 
nodes in jcr rather than a scripting language for this purpose?

Cheers
Bryce

Re: Multi-pass rendering

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Bryce,

On Mon, Jul 7, 2008 at 4:44 AM, Bryce Ewing <br...@smx.co.nz> wrote:
> ...I am wondering if there is any way to do a two (or more) pass rendering for
> content,...

I don't think this is currently possible without using workarounds.

> ...Multi rendering:
>   GET /alpha/beta.html
>   ... (not sure about this part) ...
>   uses two scripts to render the content, one which takes it from source to
> intermediary then a second one to render to html...

What could work (as a temporary solution) might be for your script to
make another http request that generates the first format, captures
that output and provides it to the module (FOP in your example) that
generates the second format.

But maybe someone has a better idea about how to do pipelines with the
current codebase?

Note that you could also create a specific servlet for this FOP/PDF
case, wire it to .pdf requests and have it use the repository document
view XML as input to an xslt transform script, that feeds into FOP
(see http://xmlgraphics.apache.org/fop/0.94/embedding.html).

>... Maybe something like this would work?
>   GET /alpha/beta.xml.html
>   resource /alpha/beta.xml (which has sling:resourceType = "test2")
>   uses /apps/test2/html.ftl to render the node beta.xml -> beta.xml.html
>   resource /alpha/beta (which has sling:resourceType = "test1")
>   uses /apps/test1/html.ftl to render the node beta -> beta.xml...

Do you mean encoding in the URL the steps used to generate the
response? I don't like that too much.

I'd prefer implementing real pipelines, using a specific *script*
extension to control a simple pipeline engine:

GET /foo/bar.pdf (resource type foo)
-> handled by /apps/foo/pdf.pipeline script

Where pdf.pipeline might be a simple pipeline control language:

transform /apps/foo/xslt/xslfo.xsl
serialize org.apache.sling.serializers.fop
  options outputFormat=pdf

Carsten mentioned Commons Sandbox Pipeline as something that might
help implementing this,
(http://markmail.org/message/2mtvwt4cxfpkgkas), and there's also the
experimental Cocoon Corona project, a minimal version of Cocoon that
includes pipelines.

So currently (and I'd love to be proved wrong on this one) I think
you'd have to resort to workarounds to do this (or implement a custom
.pdf servlet), and I think we need to introduce simple pipelines for
such cases at some points. Contributions are most welcome as usual ;-)

-Bertrand




>
> A specific example of where this would come in handy would be:
>   /alpha/beta -> /alpha/beta.xml -> /alpha/beta.xml.pdf (where the xml step
> is fop)
>
> Maybe I am going down a completely wrong track with the multi-pass rendering
> so more specifically how would I render a pdf (via first creating fop)?
>
> Cheers
> Bryce
>



-- 
  Bertrand Delacretaz
  http://www.codeconsult.ch

Re: Image rendering (image creation / manipulation)

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Bryce,

On Thu, Jul 17, 2008 at 8:30 AM, Bryce Ewing <br...@smx.co.nz> wrote:
> ...Yes, just the jai-core libraries are required (there are two included in the
> releas of jai-core, jai-core jar and jai-codec jar - both covered by the
> same license)....

If you want to use jai-core, [3] indicates that we cannot put stuff
that's under this "JAVA ADVANCED IMAGING DISTRIBUTION LICENSE (VER.
1.1.X)" [4] in a Maven repository, as (IIUC) the license specifies
that the recipient must explicitely accept the JDL license.

This means that if your code uses jai-core, we'd have to instruct
users to download the libraries manually and add them to their Maven
repository themselves.

As an alternative, it seems like Apache Batik includes some or all of
that stuff, could you have a look at [1] and see if that would be
useful? According to [2] those libraries have been donated to Batik
some time ago, so that might not be the latest stuff, what do you
think?

-Bertrand

[1] http://svn.apache.org/repos/asf/xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/image/
[2] http://markmail.org/message/m66kvpjppq26kmuj
[3] http://markmail.org/message/tl3nw4mcixpaxld4
[4] https://jai.dev.java.net/jdl-jai.pdf

Re: Image rendering (image creation / manipulation)

Posted by Bryce Ewing <br...@smx.co.nz>.
Hi Bertrand,

Yes, just the jai-core libraries are required (there are two included in 
the releas of jai-core, jai-core jar and jai-codec jar - both covered by 
the same license).

Hopeful to have something to show in this area sometime early next week.

Cheers
Bryce

Bertrand Delacretaz wrote:
> Hi,
>
> On Fri, Jul 11, 2008 at 3:43 PM, Bryce Ewing <br...@smx.co.nz> wrote:
>   
>> ...Assuming there are no licensing issues with the JAI library (Bertrand have
>> you had a chance to look at this?) I will start to put together a sling
>> image bundle based around JAI and Sanselan....
>>     
>
> Can you confirm that in this case you'll need only the jai-core
> library? If yes I can try to find out if we're allowed to use it, as
> it uses a specific license (JDL) that's not currently mentioned  at
> [1].
>
> -Bertrand
>
> [1] http://www.apache.org/legal/resolved.html
>   

Re: Image rendering (image creation / manipulation)

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Fri, Jul 11, 2008 at 3:43 PM, Bryce Ewing <br...@smx.co.nz> wrote:
> ...Assuming there are no licensing issues with the JAI library (Bertrand have
> you had a chance to look at this?) I will start to put together a sling
> image bundle based around JAI and Sanselan....

Can you confirm that in this case you'll need only the jai-core
library? If yes I can try to find out if we're allowed to use it, as
it uses a specific license (JDL) that's not currently mentioned  at
[1].

-Bertrand

[1] http://www.apache.org/legal/resolved.html

Re: Image rendering (image creation / manipulation)

Posted by Bryce Ewing <br...@smx.co.nz>.
After checking out the code and having more of a look at this library I 
have a better understanding of what it is.  This is a replacement of the 
ImageIO library from sun, but the JAI library would still be required 
for image manipulation.

What are the thoughts around using this library as part of built in 
support into sling for image manipulation?  The issue I see would be 
that since this library is still in incubation that this would mean the 
sling image bundle wouldn't be able to be released until this project 
also comes out of incubation (correct me if I am wrong on this 
point).... I also see that as a benefit for the Sanselan project as it 
would help "push" it along.

Assuming there are no licensing issues with the JAI library (Bertrand 
have you had a chance to look at this?) I will start to put together a 
sling image bundle based around JAI and Sanselan.

Cheers
Bryce

P.S. Carsten given I will be using Sanselan in this bundle I will have 
to get involved in the project ;)

Carsten Ziegeler wrote:
> Bryce Ewing wrote:
>>
>> I also noted when searching for alternatives:
>>    http://incubator.apache.org/sanselan/site/index.html
>> Which looks interesting (though I have spent all of about 20 mins 
>> looking at it).  I do notice however that Carsten is set as lead on 
>> this project in jira so maybe he might know something more about it?
>>
> Sanselan is a very nice project which allows you to read some images 
> and their meta data and to write a few formats. Its a pure java lib.
>
>> Maybe even pluggable?
> Internally it's pluggable, but there's currently no way to add own 
> plugins.
> But :) we're desperately looking for new ideas, improvements etc. So 
> you - and everyone else for course - is welcome to join the project.
>
> Thanks
> Carsten

Re: Image rendering (image creation / manipulation)

Posted by Carsten Ziegeler <cz...@apache.org>.
Bryce Ewing wrote:
> 
> I also noted when searching for alternatives:
>    http://incubator.apache.org/sanselan/site/index.html
> Which looks interesting (though I have spent all of about 20 mins 
> looking at it).  I do notice however that Carsten is set as lead on this 
> project in jira so maybe he might know something more about it?
> 
Sanselan is a very nice project which allows you to read some images and 
their meta data and to write a few formats. Its a pure java lib.

> Maybe even pluggable?
Internally it's pluggable, but there's currently no way to add own plugins.
But :) we're desperately looking for new ideas, improvements etc. So you 
- and everyone else for course - is welcome to join the project.

Thanks
Carsten
-- 
Carsten Ziegeler
cziegeler@apache.org

Re: Image rendering (image creation / manipulation)

Posted by Bryce Ewing <br...@smx.co.nz>.
In trying to find the right links for you I found things that I hadn't 
before.  Previously I was looking at:
    
http://java.sun.com/products/java-media/jai/downloads/download-1_1_2_01.html
Which is where you are pointed to if you try to get JAI from maven:
    http://mvnrepository.com/artifact/javax.media/jai_core
Though that seems a bad option

The libraries that I have had experience using are:
    JAI:
        https://jai.dev.java.net/
    And ImageIO:
        https://jai-imageio.dev.java.net/

Both of these have native accelerated code versions (but also have in 
the case of JAI a pure java version, and for ImageIO it doesn't require 
the native code).

I am not sure what the licenses are like in regards to use in the 
project, very interested in your input on that?

I also noted when searching for alternatives:
    http://incubator.apache.org/sanselan/site/index.html
Which looks interesting (though I have spent all of about 20 mins 
looking at it).  I do notice however that Carsten is set as lead on this 
project in jira so maybe he might know something more about it?

Maybe even pluggable?

Cheers
Bryce


Bertrand Delacretaz wrote:
> Hi,
>
> On Thu, Jul 10, 2008 at 7:38 AM, Bryce Ewing <br...@smx.co.nz> wrote:
>   
>> ...After having a bit of time to think about this I think your suggestion to
>> have a java component to do this would be a good idea, and if then there is
>> a specific image scripting language built around that then so be it....
>>     
>
> Sounds good!
>
>   
>> ...Have spent a bit of time over the past few days looking into and trying to
>> integrate JAI and ImageIO into a bundle built by maven etc. etc. (and half
>> the time spent beating my head against a wall).  I am not sure how well
>> using these libraries will work due to having to download them from Sun's
>> site rather than automatically getting them from a maven repository....
>>     
>
> Is that because of their licenses that they cannot be put in a Maven
> repository? If you can point me to the exact libraries that you'd like
> to use, I can have a look.
>
> -Bertrand
>   

Re: Image rendering (image creation / manipulation)

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Thu, Jul 10, 2008 at 7:38 AM, Bryce Ewing <br...@smx.co.nz> wrote:
> ...After having a bit of time to think about this I think your suggestion to
> have a java component to do this would be a good idea, and if then there is
> a specific image scripting language built around that then so be it....

Sounds good!

> ...Have spent a bit of time over the past few days looking into and trying to
> integrate JAI and ImageIO into a bundle built by maven etc. etc. (and half
> the time spent beating my head against a wall).  I am not sure how well
> using these libraries will work due to having to download them from Sun's
> site rather than automatically getting them from a maven repository....

Is that because of their licenses that they cannot be put in a Maven
repository? If you can point me to the exact libraries that you'd like
to use, I can have a look.

-Bertrand

Re: Image rendering (image creation / manipulation)

Posted by Bryce Ewing <br...@smx.co.nz>.
Hi Bertrand,

After having a bit of time to think about this I think your suggestion 
to have a java component to do this would be a good idea, and if then 
there is a specific image scripting language built around that then so 
be it.

Have spent a bit of time over the past few days looking into and trying 
to integrate JAI and ImageIO into a bundle built by maven etc. etc. (and 
half the time spent beating my head against a wall).  I am not sure how 
well using these libraries will work due to having to download them from 
Sun's site rather than automatically getting them from a maven repository.

So this has set me back a bit.

Bertrand Delacretaz wrote:
> Creating a java component (in a bundle) that implements these
> operations would make that usable from any scripting language and
> servlet, for example:
>
>   // myResourceType.png script
>   var s = sling.getService(org.apache.sling.imaging.Processor);
>   var p = s.getImageProcessor();
>   if(request.selectors[0] == "small") {
>     p.scale = 0.5;
>   } else {
>     p.scale = 1;
>   }
>   p.rotation = 90;
>   p.outputFormat = png;
>   p.watermark = currentNode.getPath() + ".watermark.png";
>   p.metadata.title = currentNode.title;
>   p.render(currentNode,response);
>
> And the image processor might also provide a simple way to store the
> output in the repository, as an option to dynamic rendering.
>   
...
> Thanks for your suggestions, and I'm sure we'll do our best to help if
> you're willing to work on this.
>
> I'm sure you notice my "subtle" hints to people who might contribute
> useful stuff to Sling ;-)
>
> Considering that the core is fairly stable now, and that important
> functions like what you describe are still missing, I think it's a
> really good time to get involved.
>
> -Bertrand
>   
Very interested in working on this (doing this outside normal work hours 
as a side project, though using sling within work for more general site 
development).

Cheers
Bryce

Re: Image rendering (image creation / manipulation)

Posted by paksegu <pa...@yahoo.com>.
On my future todo list was to see how well I can integreate EMB JSR 86 with Sling, especially the MFB beans can serve as libraries for image manipulation and watermarking and a whole lot more. Please have a look at http://www.alphaworks.ibm.com/tech/emb 

Ransford Segu-Baffoe

paksegu@yahoo.com

https://serenade.dev.java.net/
http://www.noqturnalmediasystems.com/

--- On Mon, 7/7/08, Bertrand Delacretaz <bd...@apache.org> wrote:

From: Bertrand Delacretaz <bd...@apache.org>
Subject: Re: Image rendering (image creation / manipulation)
To: sling-dev@incubator.apache.org
Date: Monday, July 7, 2008, 3:15 AM

Hi Bryce,

On Mon, Jul 7, 2008 at 6:48 AM, Bryce Ewing <br...@smx.co.nz> wrote:
> ...I am thinking of creating a way of doing image rendering through sling
and
> thought I would first check with the community as to whether this has been
> thought of, and whether there are any thoughts on how this may work....

We don't have any concrete plans at the moment, but what you suggest
looks useful.

>... Thoughts that I have had as to what this can be used for are (among
others):
>   * scaling
>   * rotation
>   * watermarking
>   * layering (i.e. use one image as background another as foreground)
>   * format changing e.g. png -> jpg
>   * quality change (to reduce size of say jpg)...

Creating a java component (in a bundle) that implements these
operations would make that usable from any scripting language and
servlet, for example:

  // myResourceType.png script
  var s = sling.getService(org.apache.sling.imaging.Processor);
  var p = s.getImageProcessor();
  if(request.selectors[0] == "small") {
    p.scale = 0.5;
  } else {
    p.scale = 1;
  }
  p.rotation = 90;
  p.outputFormat = png;
  p.watermark = currentNode.getPath() + ".watermark.png";
  p.metadata.title = currentNode.title;
  p.render(currentNode,response);

And the image processor might also provide a simple way to store the
output in the repository, as an option to dynamic rendering.

> ...So say /img/test is a png image (with sling:resourceType =
"abc/def") and I
> requested /img/test.jpg that something would reformat the image from png
to
> jpg.  If I requested /img/test.small.jpg the image would be reduced and
the
> format changed...

Scripting, as above, will allow you to use the "small" selector
easily.

> ...So I guess the most "basic" way of doing this would be to
write a servlet
> that specifically did a certain type of image creation / manipulation....

As you also mention, a service that provides an image processor
component is more flexible.

> ...One of the issues I see with this is that it would require the imageio
and
> jai libraries to be added somewhere that would then be visible to this
even
> though in most cases nobody would use jsp for this etc.  Also I don't
think
> this would be that easy for someone who doesn't know a reasonable
amount
> about jai and imageio....

OSGi allows you to "hide" those libraries inside a bundle, and expose
just the service interface.

I'm not familiar with those libraries, but it's certainly possible to
write a facade that exposes image operations so that they can be used
as above, taking a Node as input, as long as the Node contains image
file data. At least for basic usage, and maybe provide a more direct
access to the libraries for advanced use.

> ...What I have been thinking about and what I am proposing is another
scripting
> bundle that is specifically used for image creation and manipulation. 
This
> would then have some sort of source (still thinking about how this would
> work) that would define the processing to perform.  Initial thoughts are
> something along the lines of a set of parameterized JAI operators, e.g.
> SubsampleAverageDescriptor, UnsharpMaskDescriptor, AddDescriptor....

I also thought about an image processing language at first, but I
think the above example where a script drives an image processor
component is more flexible and requires less work to implement. And
also allows offline processing of images, where repository events
trigger java code or scripts that process and store ready to use
images.

> ...Would be interested in any feedback, other options etc. before I start
> design / development of this....

Thanks for your suggestions, and I'm sure we'll do our best to help if
you're willing to work on this.

I'm sure you notice my "subtle" hints to people who might
contribute
useful stuff to Sling ;-)

Considering that the core is fairly stable now, and that important
functions like what you describe are still missing, I think it's a
really good time to get involved.

-Bertrand


      

Re: Image rendering (image creation / manipulation)

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Bryce,

On Mon, Jul 7, 2008 at 6:48 AM, Bryce Ewing <br...@smx.co.nz> wrote:
> ...I am thinking of creating a way of doing image rendering through sling and
> thought I would first check with the community as to whether this has been
> thought of, and whether there are any thoughts on how this may work....

We don't have any concrete plans at the moment, but what you suggest
looks useful.

>... Thoughts that I have had as to what this can be used for are (among others):
>   * scaling
>   * rotation
>   * watermarking
>   * layering (i.e. use one image as background another as foreground)
>   * format changing e.g. png -> jpg
>   * quality change (to reduce size of say jpg)...

Creating a java component (in a bundle) that implements these
operations would make that usable from any scripting language and
servlet, for example:

  // myResourceType.png script
  var s = sling.getService(org.apache.sling.imaging.Processor);
  var p = s.getImageProcessor();
  if(request.selectors[0] == "small") {
    p.scale = 0.5;
  } else {
    p.scale = 1;
  }
  p.rotation = 90;
  p.outputFormat = png;
  p.watermark = currentNode.getPath() + ".watermark.png";
  p.metadata.title = currentNode.title;
  p.render(currentNode,response);

And the image processor might also provide a simple way to store the
output in the repository, as an option to dynamic rendering.

> ...So say /img/test is a png image (with sling:resourceType = "abc/def") and I
> requested /img/test.jpg that something would reformat the image from png to
> jpg.  If I requested /img/test.small.jpg the image would be reduced and the
> format changed...

Scripting, as above, will allow you to use the "small" selector easily.

> ...So I guess the most "basic" way of doing this would be to write a servlet
> that specifically did a certain type of image creation / manipulation....

As you also mention, a service that provides an image processor
component is more flexible.

> ...One of the issues I see with this is that it would require the imageio and
> jai libraries to be added somewhere that would then be visible to this even
> though in most cases nobody would use jsp for this etc.  Also I don't think
> this would be that easy for someone who doesn't know a reasonable amount
> about jai and imageio....

OSGi allows you to "hide" those libraries inside a bundle, and expose
just the service interface.

I'm not familiar with those libraries, but it's certainly possible to
write a facade that exposes image operations so that they can be used
as above, taking a Node as input, as long as the Node contains image
file data. At least for basic usage, and maybe provide a more direct
access to the libraries for advanced use.

> ...What I have been thinking about and what I am proposing is another scripting
> bundle that is specifically used for image creation and manipulation.  This
> would then have some sort of source (still thinking about how this would
> work) that would define the processing to perform.  Initial thoughts are
> something along the lines of a set of parameterized JAI operators, e.g.
> SubsampleAverageDescriptor, UnsharpMaskDescriptor, AddDescriptor....

I also thought about an image processing language at first, but I
think the above example where a script drives an image processor
component is more flexible and requires less work to implement. And
also allows offline processing of images, where repository events
trigger java code or scripts that process and store ready to use
images.

> ...Would be interested in any feedback, other options etc. before I start
> design / development of this....

Thanks for your suggestions, and I'm sure we'll do our best to help if
you're willing to work on this.

I'm sure you notice my "subtle" hints to people who might contribute
useful stuff to Sling ;-)

Considering that the core is fairly stable now, and that important
functions like what you describe are still missing, I think it's a
really good time to get involved.

-Bertrand

Re: Image rendering (image creation / manipulation)

Posted by Torgeir Veimo <to...@pobox.com>.
On 7 Jul 2008, at 14:48, Bryce Ewing wrote:

> One of the issues I see with this is that it would require the  
> imageio and jai libraries to be added somewhere that would then be  
> visible to this even though in most cases nobody would use jsp for  
> this etc.  Also I don't think this would be that easy for someone  
> who doesn't know a reasonable amount about jai and imageio.


Our experience with adding image manipulation capabilities to our  
product has been that JAI is possible to use, but in practise requires  
too much memory and / or is too slow for real usage. You be better off  
writing a wrapper around the "convert" utility of ImageMagick.

It would be handy to have an open source utility library that would be  
easy to "plug into" sling, with different backends for image  
manipulation implemented either with JAI or wrappers as described.

-- 
Torgeir Veimo
torgeir@pobox.com





Image rendering (image creation / manipulation)

Posted by Bryce Ewing <br...@smx.co.nz>.
Hi,

I am thinking of creating a way of doing image rendering through sling 
and thought I would first check with the community as to whether this 
has been thought of, and whether there are any thoughts on how this may 
work.

Thoughts that I have had as to what this can be used for are (among others):
    * scaling
    * rotation
    * watermarking
    * layering (i.e. use one image as background another as foreground)
    * format changing e.g. png -> jpg
    * quality change (to reduce size of say jpg)

So say /img/test is a png image (with sling:resourceType = "abc/def") 
and I requested /img/test.jpg that something would reformat the image 
from png to jpg.  If I requested /img/test.small.jpg the image would be 
reduced and the format changed.

So I guess the most "basic" way of doing this would be to write a 
servlet that specifically did a certain type of image creation / 
manipulation.  But this seems a little tedious to me, and not very 
customizable by someone in the future.  Another thought would be that 
something like JSP or Groovy would be used to do the image manipulation 
and there was a script that did this say: /apps/abc/def/jpg.jsp

One of the issues I see with this is that it would require the imageio 
and jai libraries to be added somewhere that would then be visible to 
this even though in most cases nobody would use jsp for this etc.  Also 
I don't think this would be that easy for someone who doesn't know a 
reasonable amount about jai and imageio.

What I have been thinking about and what I am proposing is another 
scripting bundle that is specifically used for image creation and 
manipulation.  This would then have some sort of source (still thinking 
about how this would work) that would define the processing to perform.  
Initial thoughts are something along the lines of a set of parameterized 
JAI operators, e.g. SubsampleAverageDescriptor, UnsharpMaskDescriptor, 
AddDescriptor.

Maybe not strictly a script either but a set of nodes in the repository 
which makes up the "script"?

Would be interested in any feedback, other options etc. before I start 
design / development of this.

Cheers
Bryce