In website operation, images are key elements that attract users and enrich content, but large image files often slow down page loading speed, affecting user experience and search engine optimization. Anqi CMS understands this point and therefore provides a very convenient and efficient solutionthumbThe filter can help us easily convert the original image into a thumbnail version suitable for web display, without manual processing, greatly improving the efficiency of content publishing and the overall performance of the website.
Core function analysis:thumbThe principle of the filter.
This namedthumbThe filter, is a powerful tool built into the Anqi CMS template engine.Its core function is to, when you obtain the URL of the original image on a website, simply apply this filter and the system will automatically generate and return a thumbnail version URL corresponding to the image.
For example, if your original image URL ishttps://yourdomain.com/uploads/2023/full_size_image.jpgthrough.thumbAfter the filter is processed, you might get a similarhttps://yourdomain.com/uploads/2023/full_size_image_thumb.jpgThe thumbnail URL. The benefits are evident: it avoids the bandwidth waste and loading delay caused by directly loading the original large image, ensuring that the image can be presented quickly on various devices and network environments, greatly enhancing the smoothness of user browsing on the website.
Whether it is the cover image of the article (usually througharchiveDetailorarchiveListTags retrieved from comments.item.Thumboritem.LogoField), category thumbnail (approved throughcategoryDetailObtainedcategory.ThumbField), or other images uploaded via the backend, as long as the original image URL can be obtained,thumbFilters can be put to good use. When used in templates, its syntax is concise and clear, usually written as{{ original_image_url|thumb }}.
Behind the scenes: thumbnail generation strategy and configuration
Of course,thumbThe intelligence of the filter does not come from nowhere, it is backed by a set of precise image processing strategies, which can be flexibly configured in the "Content Settings" of the Anqi CMS backend.
In the "Content Settings", you can find the option "Thumbnail Processing Method", the system provides three mainstream scaling modes:
- Scale proportionally to the longest sideThis method maintains the original aspect ratio of the image, resizing the longest side to the specified dimensions while the other side is proportionally reduced.This can fully display the image content, but the final size may not be fixed.
- Fill the longest side: If you need a fixed-size thumbnail without cropping the image content, this method is very suitable.It will resize the image proportionally and center it, filling the parts that are not enough with white (or other preset colors) to get a thumbnail of a fixed size.
- Trim according to the shortest edge: When you need a strictly fixed-size thumbnail and are not concerned about cropping part of the edge content, you can choose this method.The image will be cropped in the center to ensure the shortest side reaches the specified size.
In addition to the processing method, you can also accurately set the "thumbnail size".Reasonably setting the size can further optimize the image volume and accelerate page rendering.For example, if your list page only needs thumbnails with a width of 200 pixels, the system will generate and provide images of that size according to your configuration, rather than directly cropping or resizing the original large image.
In addition, the system also supports setting a "default thumbnail" to ensure that there is a placeholder image even if some content does not upload an image, maintaining the uniformity of the website layout.When your image processing strategy (such as size or processing method) changes, you can use the 'Batch regenerate thumbnail' feature to one-click update all the thumbnails on the site, saving the trouble of a lot of manual operations.These detailed configuration options,赋予了thumbThe filter's great flexibility and efficiency allows the website to ensure both visual effects and performance in image display.AnQi CMS also provides features such as 'Whether to enable Webp image format' and 'Whether to automatically compress large images', further enhancing the image optimization capability.
Practical training: Efficiently using in templatesthumbFilter
In the actual template development, usethumbThe filter is very intuitive. Suppose you are looping through a website's Banner image list and want them to be displayed as thumbnails, you can write the template code like this:
{% bannerList banners %}
{% for item in banners %}
<a href="{{item.Link}}" target="_blank">
<img src="{{ item.Logo|thumb }}" alt="{{item.Alt}}" />
<h5>{{item.Title}}</h5>
</a>
{% endfor %}
{% endbannerList %}
In this example,item.LogoThe original URL of the Banner image is obtained. By adding|thumbThe system will automatically retrieve or generate the thumbnail version URL of the image while rendering the page and assign it to<img>label'ssrcProperty. In this way, when users visit the page, the browser will load smaller and faster thumbnails instead of the original large image.
This example shows.thumbHow does the filter seamlessly integrate into the template. Whether it is an article list, product display, or any scenario that requires optimizing image loading speed, you can apply it in a similar way.It greatly simplifies the process of image management and optimization, allowing content creators to focus on the content itself without worrying about image size and format issues.
Conclusion
thumbThe filter is a powerful and practical feature provided by Anqi CMS in content operation and website performance optimization.It simplifies complex image processing tasks into a simple template tag, allowing us to focus on content creation while ensuring that the website is always presented in a **state to visitors, effectively enhancing user experience and the professionalism of the website.By using flexible configuration options in the background, we can adjust the thumbnail generation rules according to the specific needs of the website, realize fine-grained image management, and ensure that the website content maintains beauty while also having excellent loading performance.
Common questions
Q1:thumbWhere are the thumbnails generated by the filter stored specifically? Will they occupy a lot of server space?The Anqi CMS usually stores the generated thumbnails in a subdirectory of the original image path, or adds a specific identifier to the filename (such as_thumb), to distinguish the original image. These thumbnails are generated on demand based on the size and processing method configured on the backend.Because they are optimized small-sized images, they usually will not significantly increase server storage space, and can significantly reduce bandwidth consumption, which is a positive optimization for the overall resource use of the website.
**Q2: If I modify the thumbnail size setting in the background, the image on the front-end page will immediately update to the new size