I have a spring web app that serves html files with nested black and white images. These images are in <img> tags on the front end, and served statically on the back-end using a ResourceHandlerRegistry and a ResourceHandler.
I've recently added a "Dark Mode". Switching to Dark Mode updates the CSS file that's in use. I've created a color-inverted version of each image. I'd like to serve images with inverted colors when the user is in "Dark Mode", and the non-inverted versions of the images when the user is not.
All of my images are currently in a folder /resources/img. Ideally, I'd like to resolve the resources in a way that the system will check for an image in /resources/img/dark, /resources/img/light, and if neither is found, falls back to checking in /resources/img.
I haven't found this kind of thing for static resources, is there any way to do this in Spring?
I didn't find a way to do this (though I don't doubt there's a way) through Spring. Instead, I added a CSS rule to images in dark mode: filter: invert(1).
Related
I have a lot galleries displayed with Lightbox2 and it works fine.
Now I want to delete the larger version of the pictures, but keep the gallery with the thumbnails for visitors.
How can I manage, that lightbox2 displays an alternative image, if the given file in the html is not existing?
I couldn't find an option in lightbox.js to handle with missing targets.
I had the same question, but after a little research I decided that Lightbox2 is not the right place to handle missing images. Instead, that should be handled at the server or application level.
The web server will respond with a 404 error for any missing resource, whether a web page, image, or anything else. In most cases, it also returns a small HTML page to alert the user (such as this example at Google).
You can usually configure your server or application to return a default 404-style image instead of an HTML page if the requested resource was an image. That will then be displayed to the user instead of the broken image symbol.
How you do this of course depends on the particular server/application stack you are using, but here is a good solution for Apache.
I am working on an xpages app, where the client wants to restrict the size of images that are pasted into the document. I have restricted docs with the upload component, but not with a pasted image.
Has anyone done anything like this?
Thanks
walt
Yes it is possible, I haven't done this but there are a few ways you could go about it.
Excuse me if you already know this, but it is worth pointing out for anyone who comes across this question in the future, RichText as we knew it from Notes/Domino is not used XPages, it is all MIME. When I started Xpages I knew nothing about MIME so after understanding it all I have written a little summary on my blog to help anyone get used to the idea. If you are going to do anything with the InputRichText control and File Uploads etc. it is worth getting familiar with MIMEEntity's.
http://camerongregor.com/2016/04/21/webmail-ui-you-must-learn-about-mime/
There are 2 ways that images can make it into the 'rich text field', either uploaded using the 'Image' button on the editor toolbar, or alternatively in some web browsers, the image can be pasted from the clipboard. The 2 different methods will include the image in 2 different ways
Uploaded
If the image is uploaded, then the image becomes a multipart/related mime entity of some sort of image/jpeg, image/png etc., related to the text/html. Between the time that the image is uploaded, and the time that the Document is saved, the image file will be located on the server's disk, in the xpages persistence folder associated with the Document e.g.
xsppers_directory/application-id/session-id/document-id/someimage.png
Pasted
When pasted the image is not uploaded as a file to the server's persistence folder, but is instead included within the text/html as a data URI image (as Stephan mentioned in the comment above).
So, if you want a true solution you will need to address both avenues.
Handling Pasted images
I have shared a plugin on my blog which blocks pasted images, so this could be used to eliminate the 'paste' avenue altogether, and force users down the upload avenue.
http://camerongregor.com/2016/11/14/preventing-pasting-of-images-in-ckeditor/
Alternatively, if you are happy with having smaller pasted images, you could just 'restrict' it by modifying the plugin so that it checks the 'length' of the data URI (as Stephan suggested above) and allows the paste if the length is below your predetermined limit.
If even more alternatively, you could find some sort of client side javascript library that will resize images and do it there in the client before the paste.
Or another server-side option is you could process the contents of the 'text/html' MIMEEntity when saving, and find any img tag's that used Data URI's and strip it out, resize the image using some server side library such as ImageMagick and replace it.
Handling Uploaded Images
For uploaded images, an intense solution would be to extend the InputRichText control (similar to how the have demonstrated in the Mastering Xpages 2nd edition) and override the processAjaxRequest event so that it resizes the image during the process of uploading of the image and putting it in the persistence folder. You could resize it there and then using something like ImageMagick.
Or a less intense version would be to process the 'pending' attachments during a before save event. If you get the DominoRichTextItem from the DominoDocument, you should be able to iterate through the Attachments, checking their attachment state, there will be a state which means 'pending/about to upload' and for these ones you can process them while they are in the persistence folder, before they are finally attached to the document.
Finally if you don't want the xpages runtime / persistence directory to be involved, you could do it all after save, just using the backend NotesDocument and MimeEntity processing. Extract the Image MimeEntities to disk, process them with ImageMagick or similar, and then re-attach them.
Someone else may have a simpler solution that I haven't thought of but at least this gives you some idea of what may be involved.
I'm coming from a php/mysql background. I'm most familiar with the Kohana PHP framework and I'm trying to learn Docpad. I have a loose understand at this point and I've built out my first website and blog. Static content makes a lot of sense to me on Docpad.
I'm working on my photography site where I want to be able to upload new images to a portfolio. The backend needs to handle an uploaded high-resolution image and create several different copies at different resolutions of the image. My biggest question is how do I keep track of the image meta data that I want to display? Do I generate a physical file for each image that has all the particulars I want to track and use those files as my searchable database, much like how blog posts are setup?
Or should I go the route of using something like MongoDB to store image data there where it can be queried and plugged into a layout?
Regarding handling POST or GET data, should I be reading up on the express.js docs? I'm not really sure where to turn for that.
Wordpress uses TimThumb to re-size it's images: How does WordPress.com resize images dynamically?
Then there is this re-sizing library for node: node package for file attachments and image resizing
If you wanted to created like 3 different image sizes and use the backbone collection in DocPad, then you'd add your different re-sized images to those three different collections/folders. For access the images you might just be able to do it via it's file name. So when you copy, re-size and rename the image, in the rename step, concat the image size at the end, like: coolPhoto-med.jpg and then you could just do hard links to get to the image like /spring-collection/med/coolPhoto-med.jpg or you could use query engine to access them.
The file model has a meta attribute: https://github.com/bevry/docpad/blob/master/src/lib/models/file.coffee#L17
I've yet to learn how to use it yet though.
I know we chatted yesterday on #docpad IRC but I just wanted to answer you here too. If you do code something that re-sizes images for DocPad, please do consider putting it up on Github to share with the community.
I'm using the Asp Sprite and Image Optimization Framework located here to handle any css sprites in my site. Depending on the brower the framework generates two different links pointing to these two files
/App_Sprites/highCompat.css - ie9, firefox, chrome
/App_Sprites/lowCompat.css - ie6, ie7
Unfortunately the css files are not minified and cannot be moved from their current location.
I have my own minification engine though wrapping around the Ajaxmin library where I use a handler to fling out compressed css on the fly.
This will capture a path like this.
/css.axd?path=reset.css|style.css|helpers.css
How could I with MVC capture the request and rewrite it so the css is served through my minifier?
Cheers!
Pretty easy, really: Put the CSS somewhere other than where the URI in your markup points.
IIS won't run route handlers if the physical file exists. So if your site has a physical ~/App_Sprites/highCompat.css file, your app won't be able to intercept it (though you could do this with a HttpModule). But if you put the file elsewhere and have a App_SpritesController then you can handle things as usual in MVC.
So either write an HttpModule (this would probably be my choice) or, if you must do it through MVC, relocate the file.
I have used a tag with attribute src="mydirectory/myimage.gif.
If the image is not present in the directory , how can i avoid showing a default break image inside my img tag ?
this is present in chrome and I.E browsers but not in Firefox...
Any idea to avoid this ?
Thank You ...
A popular way to do it is to edit your web server.
for example, on apache, if you store all your images in a directory "http://host/images",
and add a .htaccess file to that directory to redirect all 404s to serve a default blank image.
see here:
Can Apache serve a default file instead of a 404?
but you are serving an image instead of any kind of file.
There are other ways of doing it, for example, if you have access to a server side language (php, ruby) you can check if an image file exists on your server first, if not, serve a default image.
Or use the javascript method as mentioned by Pekka.
You can do it with your web server, server side / client side script.
I dont know if there's a way to do it with CSS, or other techniques, sure others will fill in.
Hope that is helpful.