<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Paul,<div><br></div><div>I found this in the archives: <a href="http://lists.opencms.org/pipermail/opencms-dev/2006q3/026284.html">http://lists.opencms.org/pipermail/opencms-dev/2006q3/026284.html</a></div><div><br></div><div>Alexander describes how to automatically scale down images exceeding a certain size.</div><div><br></div><div>Cheers</div><div>Henning<br>
<br><div><div>On Oct 1, 2013, at 12:12 PM, Paul-Inge Flakstad <<a href="mailto:flakstad@npolar.no">flakstad@npolar.no</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Henning,<br><br>Thank you, this makes perfect sense. :)<br><br>(Being familiar with both the scaler and the event listeners, I should have thought of using a listener - it's quite obvious.)<br><br>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. <br><br>Can you (or anyone else) tell me anything about this?<br><br>Cheers,<br>Paul<br><br>-----Original Message-----<br>From: <a href="mailto:opencms-dev-bounces@opencms.org">opencms-dev-bounces@opencms.org</a> [mailto:opencms-<a href="mailto:dev-bounces@opencms.org">dev-bounces@opencms.org</a>] On Behalf Of Henning Treu<br>Sent: 1. oktober 2013 08:59<br>To: The OpenCms mailing list<br>Subject: Re: [opencms-dev] Downscale large images automatically upon upload / create image resource<br><br>Hi Paul,<br><br><blockquote type="cite">If not, can I avoid touching core classes in OpenCms if I was to <br>create such functionality myself? (Or: Can I add-on a custom "create <br>image resource" handler class? How do I make OpenCms use it?)<br></blockquote><br>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.<br>Something like this:<br><br>@Override<br>public void initialize(CmsObject adminCms, CmsConfigurationManager configurationManager, CmsModule module) {<br><span class="Apple-tab-span" style="white-space:pre"> </span>CmsEventManager eventManager = OpenCms.getEventManager();<br><br><span class="Apple-tab-span" style="white-space:pre"> </span>LOG.info("Registering cms event listeners:");<br><span class="Apple-tab-span" style="white-space:pre"> </span>CCECmsEventListener listener = new MyCustomEventListener();<br><span class="Apple-tab-span" style="white-space:pre"> </span>listener.setCmsObject(adminCms); // set the admin cms object for future use<br><span class="Apple-tab-span" style="white-space:pre"> </span>eventManager.addCmsEventListener(listener, <br><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>new int[] { I_CmsEventListener.EVENT_RESOURCE_CREATED });<br><span class="Apple-tab-span" style="white-space:pre"> </span>LOG.info(listener.getClass().getName() + " registered."); }<br><br>In your listener you might use the CmsImageScaler. Its quite easy to use. I do it like this:<br><br>private CmsImageScaler createImageScaler(int width, int height) {<br><span class="Apple-tab-span" style="white-space:pre"> </span>CmsImageScaler scaler = new CmsImageScaler();<br><br><span class="Apple-tab-span" style="white-space:pre"> </span>scaler.setWidth(width);<br><span class="Apple-tab-span" style="white-space:pre"> </span>scaler.setHeight(height);<br><span class="Apple-tab-span" style="white-space:pre"> </span>scaler.setType(3); // preserve aspect ratio<br><span class="Apple-tab-span" style="white-space:pre"> </span>scaler.setRenderMode(Simapi.RENDER_QUALITY); // QUALITY or SPEED<br><span class="Apple-tab-span" style="white-space:pre"> </span>scaler.setQuality(100); // JPEG compression quality<br><br><span class="Apple-tab-span" style="white-space:pre"> </span>return scaler;<br>}<br><br><br>Cheers<br>Henning<br><br><br><blockquote type="cite">Alternatively, is there a way to simply disallow upload of "large" (as defined by me) images?<br><br>Any advice is much appreciated! :)<br><br>Challenge: <br>Some editors don't bother to downscale images before uploading. This <br>is a problem, because although all our images are downscaled in-page, <br>we still link the in-page image to the original. Also, if the <br>resolution is really huge, we could run into out-of-memory situations <br>on the server when creating the downscaled versions displayed in-page <br>on the site. (Especially if OpenCms was to initiate multiple <br>downscales at roughly the same time - after flushing the image cache, <br>for example.)<br><br>Imagined solution:<br>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.<br><br>Cheers,<br>Paul<br><br>_______________________________________________<br>This mail is sent to you from the opencms-dev mailing list To change <br>your list options, or to unsubscribe from the list, please visit <br><a href="http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev">http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev</a><br><br><br><br></blockquote><br>_______________________________________________<br>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 <a href="http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev">http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev</a><br><br><br><br>_______________________________________________<br>This mail is sent to you from the opencms-dev mailing list<br>To change your list options, or to unsubscribe from the list, please visit<br><a href="http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev">http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev</a><br><br><br><br></blockquote></div><br></div></body></html>