How to convert image addresses to thumbnail format for display?

Calendar 👁️ 52

In website operation, images play a crucial role.They can not only attract the attention of users but also effectively convey information.However, very large images can severely affect the website loading speed, thereby damaging user experience and search engine rankings.Therefore, converting the image address to a thumbnail format for display has become an indispensable part of optimizing website performance.AnQiCMS provides very convenient functions in this regard, it can automatically generate and manage thumbnail images for your website, and provide flexible calling methods to help you easily meet the challenges of image optimization.

AnQiCMS automatically generated thumbnail: Smart and efficient

AnQiCMS has intelligent image processing capabilities. When you upload images on the backend or insert images in article content, the system will automatically identify and process them.

  • Automatically extract and generate: If you do not manually upload a thumbnail when publishing the document, but the document content contains images, AnQiCMS will intelligently extract the first image in the document as the thumbnail for the document.
  • Global Configuration Strategy: AnQiCMS allows you to uniformly configure the thumbnail generation strategy in the "Content Settings" section of the backend. This includes:
    • Thumbnail Processing Method: You can choose three different methods to adapt to different display requirements:
      • Scale proportionally to the longest sideThis method will display all sides of the image, with one side fixed and the other side scaled proportionally according to the image ratio to avoid distortion.
      • Fill the longest sideIf you need to fix the aspect ratio of the thumbnail but also want to display the image completely, you can choose this method.The image will be centered, and the insufficient part will be filled with white or other specified colors to reach a fixed size.
      • Trim according to the shortest edgeWhen you need a strict fixed size and do not mind cropping part of the image, this method will crop the image in the center, ensuring that the shortest edge is displayed completely, and the longest edge matches the length of the shortest edge.
    • Thumbnail sizeYou can set the specific pixel size of the thumbnail according to the actual needs of the website front-end page (for example: 200x150).Setting the size properly helps to further reduce the image size and speed up page loading.
    • Default thumbnailTo maintain the visual consistency of the website, you can upload a default thumbnail. When a document or category does not have a specific thumbnail, the system will automatically use this default image for display.
    • WebP image format: AnQiCMS supports enabling WebP image format.Enable this feature, and uploaded JPG, PNG, and other image files will be automatically converted to WebP format, which can significantly reduce the file size of images and further improve loading speed.
    • Automatically compress large imagesThe system can also automatically compress large-sized images, adjusting them to the maximum width set (for example, 800 pixels) to avoid directly loading the original large image, saving server storage space and bandwidth.

Flexibly call thumbnails in the template

In the AnQiCMS template, the image address is converted to thumbnail format for display, mainly achieved through two methods: directly referring to the system-generated thumbnail address, or using|thumbThe filter converts any image address in real time.

1. Directly reference the system preset thumbnail field

For the document (archive)、Category(category) and single page (page)等内容,AnQiCMS in its data structure usually provides pre-generated thumbnail fields for direct calling.

  • document thumbnail: In usearchiveListTags cycle to display document lists, eachitemObjects usually containitem.Thumbfields, which is the thumbnail address generated by the system according to the background configuration.

    {% archiveList archives with type="list" limit="10" %}
        {% for item in archives %}
            <a href="{{ item.Link }}">
                {% if item.Thumb %}
                    <img src="{{ item.Thumb }}" alt="{{ item.Title }}" />
                {% endif %}
                <h3>{{ item.Title }}</h3>
            </a>
        {% endfor %}
    {% endarchiveList %}
    

    On the document detail page, you can also use{{ archive.Thumb }}to get the thumbnail address of the current document.

  • Category and single page thumbnailLikewise,categoryDetailandpageDetailObjects obtained with tags usually also containThumbfield.

    {% categoryDetail categoryThumb with name="Thumb" %}
    <img src="{{ categoryThumb }}" alt="{% categoryDetail with name='Title' %}" />
    

2. Use|thumbFlexible conversion with filters

AnQiCMS provides a powerful|thumbA filter that you can apply to any image address to generate thumbnails based on global settings or specific requirements. This means that even if you have the original large image address (for exampleitem.Logo),can also be converted into a thumbnail format in the template.

<img src="{{ 图片地址 | thumb }}" alt="图片描述" />

Example: Convert the document cover logo (Logo) into a thumbnail.

Assumeitem.LogoIs the original cover image address of the document, and you want to display its thumbnail on the list page or detail page:

{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
        <a href="{{ item.Link }}">
            {% if item.Logo %}
                {# 使用 |thumb 过滤器将原始Logo图片地址转换为缩略图格式 #}
                <img src="{{ item.Logo | thumb }}" alt="{{ item.Title }}" />
            {% endif %}
            <h3>{{ item.Title }}</h3>
        </a>
    {% endfor %}
{% endarchiveList %}

So, even ifitem.LogoThe image stored is the original large image, and when displayed on the front end, it will also be processed by the AnQiCMS thumbnail, which ensures image quality and optimizes loading speed.

Specific settings and configuration: Optimize your image strategy

To make full use of the AnQiCMS thumbnail function, you must refine the configuration in the backend management interface:System settings" -> "Content settingsConfigure in detail:

  1. Thumbnail Processing Method: Choose the most suitable thumbnail processing method (aspect ratio scaling, padding, or cropping) according to your design style and content display requirements.
  2. Thumbnail size:Set the width and height accurately to match the size of the image display area on your website. This ensures that the image fits perfectly into the layout and effectively controls the file size.
  3. Default thumbnail: Upload a default image with brand characteristics as a placeholder for content without images or missing images.
  4. WebP image format: It is strongly recommended to enable this option to achieve **improved image loading performance.
  5. Automatically Compress Large Image: Turn on and set a reasonable width threshold to avoid slow websites due to unprocessed large images.
  6. batch regenerate thumbnailsIf you modify any of the above thumbnail configuration and need to generate thumbnails for the uploaded images according to the new rules, please use this feature for batch processing.This ensures that the full site images maintain consistent optimization effects.

By making the above settings and template calls, AnQiCMS ensures that your website can display image content efficiently and beautifully, thereby enhancing the user experience, improving search engine friendliness, and bringing substantial help to your content operations.


Frequently Asked Questions (FAQ)

Q1: Why did I change the thumbnail size setting on the back end, but the image display size on the front end of the website did not change immediately?A1: After modifying the thumbnail size and other 'content settings', AnQiCMS needs to regenerate thumbnails for the uploaded images.You can go to the "System Settings" -> "Content Settings" page, find the "Batch Regenerate Thumbnails" feature, click to execute, and the system will update all thumbnails according to the new settings size and processing method.In addition, browser caching may also cause display delays, you can try clearing the browser cache and then try again

Related articles

How to truncate long text content and add an ellipsis at the end to optimize list display?

In website operation, especially managing a content-rich platform, the display effect of the list page is crucial for user experience.Whether it is an article list, product overview, or news update, we hope the page is tidy and the information is clear at a glance.However, when the document content or description is too long, directly displaying it in the list often leads to layout confusion, affecting the overall aesthetics and information acquisition efficiency.At this moment, effectively truncating text and adding an ellipsis is particularly important.AnQiCMS (AnQiCMS) provides a powerful and flexible template system, in which built-in text filters can help us easily solve this problem

2025-11-08

How to safely output HTML tags in website content to avoid escaping?

In website content management, especially when content includes rich formats or user input, how to safely output HTML tags is a crucial issue.AnQiCMS (AnQiCMS) fully considered this from the beginning, its template engine defaults to escaping output variables to effectively prevent cross-site scripting attacks (XSS) and other security risks.### Understanding the Default Behavior of Template Engines The Anqi CMS template engine follows the syntax of mainstream frameworks like Django, one of its core concepts being 'Security First'

2025-11-08

How to embed mathematical formulas and flowcharts in a page and ensure correct rendering display?

In website operation, we often need to display some professional content, such as mathematical formulas involving scientific calculations, or complex flowcharts for business process descriptions.The traditional way of displaying this content is often inefficient, difficult to maintain, and also does not provide a good reading experience.AnQiCMS combines its powerful content management capabilities and support for Markdown to provide us with an elegant solution.By simply introducing some external libraries and enabling the Markdown editor, we can display the professional content correctly on the website page

2025-11-08

How to implement pagination navigation display for content list in AnQi CMS?

When using AnQiCMS to build a website, it is particularly important to have reasonable pagination navigation when displaying a large amount of content, such as article lists, product lists, etc.It not only enhances user experience, making it easier for visitors to browse and find content, but also helps search engines better crawl the website.AnQi CMS provides a very intuitive and powerful pagination tag, making it easy to display content list pagination.### Step 1: Prepare the content list data To implement pagination of the content list, you first need to use `archiveList`

2025-11-08

How to display the background custom banner (Banner) image list in the template?

The banner image on the website is an important element to attract visitors' attention and display core information.In Anqi CMS, you can flexibly customize these banner images in the background and elegantly present them in various template positions on the website.Below, we will discuss in detail how to display the custom banner image list in the template, making your website more attractive. ### Configuration and Management of Background Banner Images In the Anqi CMS backend, the management of banner images is mainly divided into two cases: global homepage banners and specific content banners. 1.

2025-11-08

How to dynamically display different content blocks based on conditions (if tag)?

In Anqi CMS, the dynamic display of website content is the key to improving user experience and operational efficiency.You often encounter such needs: you want a certain content block to appear only under specific conditions, or to display different information for different situations.At this point, the powerful conditional judgment feature of Anqi CMS - the `if` tag, can be put to good use.The Anqi CMS template system adopts a syntax similar to the Django template engine, allowing you to implement logical judgments in templates in a straightforward manner.By flexibly using the `if` tag, you can easily control the display and hide of web elements

2025-11-08

How to use a loop (for label) to traverse and display a content list?

In Anqi CMS, whether it is displaying article lists, product catalogs, navigation menus, or friend links, we will frequently deal with content lists.To dynamically display this content on the website front-end, you can't do without powerful looping functions.Today, let's delve deeper into how to use the loop (`for` tag) in Anqi CMS templates to traverse and display your content list. ### The core syntax of the `for` tag: Bring content to life The Anqi CMS template syntax is similar to Django and Blade, very intuitive.When you need to handle a set of data

2025-11-08

How to format a timestamp into a readable date and time string for display?

In Anqi CMS, formatting timestamps into readable dates: A practical guide When managing website content, we often encounter the need to display article publishing time, update time, and user registration time information.These data are usually stored in the database in the form of a string of numbers - that is, a 'timestamp'.Although computers can easily understand these numbers, they may not seem so friendly to users visiting websites.For example, seeing a number like '1678886400' is not as intuitive as '2023 March 15 10:00:00'

2025-11-08