Skip to content

Posts tagged ‘java’

2
Mar

Resize images in Java, preserving image quality

It shouldn’t be so difficult to do simple image manipulation in java.  Resizing images is a frequently-encountered need, often to create thumbnails or to shrink pictures taken from digital cameras to a reasonable display size.  But how to create thumbnails in java without sacrificing image quality?  Standard library image manipulation is severely lacking in this area.

Luckily, talented java programmers have worked to create better solutions.  I’ve thrown together an image utility, building off of the work of others, to expose a few basic image manipulation functions, namely: open (from a file, URL, InputStream or byte array), save to file, soften, resize, and resize to square.  This may be useful to your project.  Just read the important caveat toward the bottom of this post.

I make no warrantees about this utility.  If you like it, a link back to this blog would be more than welcome.

Read moreRead more

27
Feb

To sanitize user content, use an HTML parser

It is especially important, if you allow any HTML at all in user-submitted content, to sanitize that content by actually parsing the HTML and filtering it for any tags or attributes you wish to exclude. If you fail to do so, your site may be vulnerable to XSS (cross-site scripting) attacks.

Q: “But isn’t it overkill to parse the HTML?  Can’t I use other techniques, such as regular expressions or simple string replacement, to filter out dangerous tags and attributes?”  A: No, and I’ll explain why. Read moreRead more