Control dynamic servlet graphic processing (1)

Source: Internet
Author: User

Control the world-or at least control your images
As a site developer or page author, it is very difficult to cater to all these preferences. To manually perform this operation, you must convert each image on the site to the image size supported by your website. Then, you need to adjust the Image Tag on each page on the site so that each tag correctly reflects the image size. You cannot only change the width and height of the HTML img Tag without changing the image: This causes users with low bandwidth to download large images, and adjust the size of the client. If eight commonly used image sizes are provided, you can easily see how each image requires eight zooming sizes and how each page requires eight versions of image tags. This type of image management is tedious and error-prone, so you can easily understand why most websites do not provide multiple image sizes.
The problem is not about technology: it is easy to use Java programming to convert images into various sizes or formats. The problem is not about services: it is common to use Web servers to customize pages to meet the needs of individual readers. On the contrary, the problem is to combine technologies and services in a form that is easy to deploy and manage.
This article recommends a solution that uses the assumerver Pages (JSP) tag to manage your images. For example, encode image tags in HTML and provide multiple versions for each image size, as shown below:

It makes more sense to provide a tag that can automatically adjust the image size based on your preferences, as shown below:
<Util: imagesizer src = "images/LazyDog.jpg"/>
It is possible to have readers select from many sizes and make their preferences affect all images on the site, as shown in the sample browser image in 1. It is also possible to insert width and height attributes and eliminate the hassle of manually editing these tags.
Figure 1. Sample JSP page with image preferences (SMILE)
You may have never seen JSP custom tags before. Let's simply look at the syntax in this example. JSP custom tags look like HTML tags, but there are the following differences:
There is a tag named imagesizer created by the tag developer.
Tag has a prefix util, which combines the TAG set into a library, which is very similar to the package name in Java programming. You can create a new prefix or use the default name provided with the library.
This tag has a new ending tag like XML "/> ".
Like HTML tags, JSP tags can have any number of attributes. For example, the src attributes shown here can contain the subject, and the subject can contain other tags. Since we are imitating the img tag of HTML, our JSP image scaling tag will have no subject.
When the JSP page uses the custom image-sizer tag, the marked Java Implementation finds the image file, convert the image to an appropriate size (a copyright or watermark logo may be added during this process) and then provide the image to the reader. This tag makes it unnecessary for the site manager to convert images before publishing. It also simplifies the compilation of Web pages, because processing many image size preferences requires only one page. Finally, and most importantly, providing this flexibility for all your site images will win the favor of readers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.