[opencms-dev] Export scaled image programatically

Paul-Inge Flakstad flakstad at npolar.no
Fri May 13 00:23:11 CEST 2011


I'm trying to programmatically export a scaled image, and struggling.

I've created a feed, which should contain downscaled images. The feed unfortunately also needs to contain the size of each image, according to the spec.

I was able to get the correct link (e.g. img.jpg_8494839439.jpg) which will take any user straight to the exported downscaled image, but until someone requests that link, the downscaled image does not exist, and so it is "impossible" to determine its size.

This is why I want to export the downscaled image (if it does not exist) upon building the feed. It proved quite a challenge...

I've created a class library for the feed module, so all my code is in a .jar file.

I've tried this:
CmsObject guestCmso = OpenCms.initCmsObject("Guest"); // Doc says to use the guest user
String scaleParams = "__scale=w:400,h:200,q:90,t:3"; // Example scale parameters
String imageScalePath = guestCmso.getSitePath(imageResource).concat("?" + scaleParams); // imageResource is the CmsResource that is the original image
CmsStaticExportData data = OpenCms.getStaticExportManager().getExportData(imageScalePath, guestCmso);
if (sed != null) {
    OpenCms.getStaticExportManager().export(cms.getRequest(), cms.getResponse(), guestCmso, data); // cms is an initialized CmsJspActionElement instance, passed to this class by the JSP

However, it looks like "data" is always assigned a null value, probably because I'm appending the "scaleParams". But if I don't append these parameters, how else can I tell the system that I want to export a _scaled_ version and not the original???

Can someone point me to something or give an example?

(PS: I am aware that there are several workarounds for my problem, but I would really like to accomplish it the way I'm describing it here. :)

Best regards,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20110513/bde3b263/attachment.htm>

More information about the opencms-dev mailing list