[opencms-dev] Downscale large images automatically upon upload / create image resource
Paul-Inge Flakstad
flakstad at npolar.no
Wed Oct 2 14:03:20 CEST 2013
Hi Andreas,
This is exactly what I was looking for, you just made my day! Thanks :)
I added it to the wiki: http://www.opencms-wiki.org/wiki/Gallery_Overview#Image_Gallery
Cheers,
Paul
-----Original Message-----
From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Andreas Zahner
Sent: 2. oktober 2013 09:10
To: opencms-dev at opencms.org
Subject: Re: [opencms-dev] Downscale large images automatically upon upload / create image resource
Hi,
you can configure automatic downscaling of images on upload in the OpenCms configuration.
Edit the opencms-vfs.xml file below WEB-INF/config/ and add a <param> element to the CmsImageLoader ressource loader node:
<loader class="org.opencms.loader.CmsImageLoader">
<param name="image.scaling.enabled">true</param>
<param
name="image.scaling.downscale">w:800,h:600,q:97,c:transparent</param>
</loader>
You can use all parameters that are available for the image scaler.
It is also possible to exclude specific folders from the automatic downscaling process. To do so, set the property "image.size" at the folder to "unlimited". This exclusion applies only to images that are directly uploaded to that folder, and is not inherited to eventual subfolders.
Regards,
Andreas.
-------------------
Andreas Zahner
Alkacon Software GmbH - The OpenCms Experts http://www.alkacon.com - http://www.opencms.org
Am 01.10.2013 14:46, schrieb Paul-Inge Flakstad:
> Hi again Henning and list,
>
> That post was very interesting indeed, thanks! What Alexander says
> here would be *perfect*:
>
> "If you set the property "image.size" on a folder, all images uploaded
> to this folder are scaled automatically to that size after the upload."
> (paraphrased)
>
> However, I cannot get it working like this. I tested on v7 & v8 by
> setting "w:100,h:100,t:3,q:100" as value for the "image.size" property
> on the gallery folder. (It could be just the syntax, but I tried
> various other forms and none worked. Also, looking at the
> CmsImageScaler#parseParameters source, the mentioned syntax seems
> correct.)
>
> Maybe Alkacon dropped this sometime after v6.2 (which is the version
> Alex is talking about), but that seems strange...
>
> Anyone else got this working?
>
> Cheers,
>
> Paul
>
> *From:*opencms-dev-bounces at opencms.org
> [mailto:opencms-dev-bounces at opencms.org] *On Behalf Of *Henning Treu
> *Sent:* 1. oktober 2013 14:03
> *To:* The OpenCms mailing list
> *Subject:* Re: [opencms-dev] Downscale large images automatically upon
> upload / create image resource
>
> Hi Paul,
>
> I found this in the archives:
> http://lists.opencms.org/pipermail/opencms-dev/2006q3/026284.html
>
> Alexander describes how to automatically scale down images exceeding a
> certain size.
>
> Cheers
>
> Henning
>
> On Oct 1, 2013, at 12:12 PM, Paul-Inge Flakstad <flakstad at npolar.no
> <mailto:flakstad at npolar.no>> wrote:
>
>
>
> Hi Henning,
>
> Thank you, this makes perfect sense. :)
>
> (Being familiar with both the scaler and the event listeners, I should
> have thought of using a listener - it's quite obvious.)
>
> But, anyway, I seem to recall reading about some native functionality
> in OpenCms which lets you set max image size. Not sure if my memory
> can be trusted though.
>
> Can you (or anyone else) tell me anything about this?
>
> Cheers,
> Paul
>
> -----Original Message-----
> From: opencms-dev-bounces at opencms.org
> <mailto:opencms-dev-bounces at opencms.org>
> [mailto:opencms-dev-bounces at opencms.org
> <mailto:dev-bounces at opencms.org>] On Behalf Of Henning Treu
> Sent: 1. oktober 2013 08:59
> To: The OpenCms mailing list
> Subject: Re: [opencms-dev] Downscale large images automatically upon
> upload / create image resource
>
> Hi Paul,
>
>
> If not, can I avoid touching core classes in OpenCms if I was to
> create such functionality myself? (Or: Can I add-on a custom "create
> image resource" handler class? How do I make OpenCms use it?)
>
>
> there is a way to implement your own functionality like this. In
> manifest.xml there is an element <class> which lets you provide a full
> qualified class name for your custom implementation of
> I_CmsModuleAction. You can register event listeners in the initialize
> method and process EVENT_RESOURCE_CREATED events. Make sure to retain
> the admin CmsObject from the initialise method.
> Something like this:
>
> @Override
> public void initialize(CmsObject adminCms, CmsConfigurationManager
> configurationManager, CmsModule module) { CmsEventManager eventManager
> = OpenCms.getEventManager();
>
> LOG.info("Registering cms event listeners:"); CCECmsEventListener
> listener = new MyCustomEventListener();
> listener.setCmsObject(adminCms); // set the admin cms object for
> future use eventManager.addCmsEventListener(listener,
> new int[] { I_CmsEventListener.EVENT_RESOURCE_CREATED });
> LOG.info(listener.getClass().getName() + " registered."); }
>
> In your listener you might use the CmsImageScaler. Its quite easy to
> use. I do it like this:
>
> private CmsImageScaler createImageScaler(int width, int height) {
> CmsImageScaler scaler = new CmsImageScaler();
>
> scaler.setWidth(width);
> scaler.setHeight(height);
> scaler.setType(3); // preserve aspect ratio
> scaler.setRenderMode(Simapi.RENDER_QUALITY); // QUALITY or SPEED
> scaler.setQuality(100); // JPEG compression quality
>
> return scaler;
> }
>
>
> Cheers
> Henning
>
>
>
> Alternatively, is there a way to simply disallow upload of "large" (as
> defined by me) images?
>
> Any advice is much appreciated! :)
>
> Challenge:
> Some editors don't bother to downscale images before uploading. This
> is a problem, because although all our images are downscaled in-page,
> we still link the in-page image to the original. Also, if the
> resolution is really huge, we could run into out-of-memory situations
> on the server when creating the downscaled versions displayed in-page
> on the site. (Especially if OpenCms was to initiate multiple
> downscales at roughly the same time - after flushing the image cache,
> for example.)
>
> Imagined solution:
> Eliminate the problem by setting a max resolution for images. Possibly
> implemented by automatically downscaling large images upon upload /
> create. Ideally I should also be able to override the restriction on a
> per-folder basis, for those special cases when a high-res image is
> actually called for.
>
> Cheers,
> Paul
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list To change
> your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list To change
> your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list To change
> your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list To change
> your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
_______________________________________________
This mail is sent to you from the opencms-dev mailing list To change your list options, or to unsubscribe from the list, please visit http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list