In website operation, the loading speed and display effect of images directly affect user experience and search engine optimization.Especially for content management systems with a large number of images, how to efficiently generate and display thumbnails of different sizes is a crucial feature.AnQiCMS (AnQiCMS) provides a flexible and powerful solution in this aspect, making it easy to manage and display image resources.
Core advantages: Intelligent generation and flexible upload
AnQiCMS handles image resources quite meticulously.It is most reassuring feature that it can intelligently recognize and automatically generate thumbnails.This means that when you upload an image to the media library or insert an image into the article content, AnQiCMS can automatically create thumbnails of different sizes for these images according to preset rules.
In most cases, if you do not manually upload a thumbnail when publishing a document, but the document content contains images, the system will automatically extract the first image in the content as the document thumbnail.This automated processing greatly relieves the burden on content editors.Of course, you can also upload a dedicated thumbnail manually at any time, or choose a more suitable image from the existing image library to replace it.Whether it is an article, product, category, or an independent single page, you can configure a dedicated thumbnail for them to ensure that they present a visual effect in different display scenarios.
Fine control: Thumbnail management in global settings
To learn more about how AnQiCMS generates and manages thumbnails for image resources, we need to go to the back end's全局设置of内容设置Part. Here are all the core options for image processing, allowing you to make detailed adjustments according to the specific needs of the website.
Thumbnail Processing MethodIt is the core of the core, which determines how the image will be presented when scaled. AnQiCMS provides three intuitive processing methods:
- Scale proportionally to the longest side:This method will maintain the original aspect ratio of the image, ensuring that the image content is displayed completely without distortion.It will resize the image proportionally based on the longest side (either width or height) until it touches the set thumbnail size boundary.This is a good choice if you pursue complete and lossless image presentation.
- Pad to the longest edge:If you want the thumbnail to have a fixed width and height, and also want to display the entire image content without cropping, then 'pad to the longest side' is prepared for you.The system will resize the image proportionally based on the longest side, then fill the insufficient part of the image with white blocks to center the image in the fixed thumbnail area.This is especially useful for scenarios that require uniform image backgrounds or borders.
- Trim to the shortest edge:When you focus more on the visual impact of the thumbnail area and are willing to sacrifice the edges of the image to fit a fixed size, 'Crop to Shortest Side' will be your helper.The system will crop the shortest edge of the image to center it, thus generating a thumbnail that is completely in line with the specified size.This is very common in scenarios where images need to fill the entire thumbnail frame, such as in news lists, product grids, etc.
Closely coordinated with the processing methods is:Thumbnail sizeThe settings. Here you can accurately set the width and height of the thumbnail according to the design requirements of the front-end page, for example, set to200x150Pixel. Properly setting the size can effectively reduce image file size and speed up page loading.
In addition, AnQiCMS also takes special cases into consideration. You can set aDefault thumbnailWhen certain content is not specified or the system fails to automatically extract thumbnails, this default image will automatically replace the display to avoid ugly image placeholders on the page.
During the operation, the design and requirements of the website may change.If you modify the thumbnail size or processing method, do not worry that the old images will not fit.AnQiCMS providedbatch regenerate thumbnailsThe function, you can one-click to let all uploaded images be resized according to the new settings, saving the trouble of manual adjustment.
In addition to the thumbnail itself,内容设置There are some other important image processing options such asWhether to enable Webp image format(Helps reduce the size of the image),Whether to automatically compress large imagesas well asAutomatically compress to a specified width(Further optimize image size, improve loading speed), these are the key factors to enhance the overall performance of website image resources.
Template call: Display thumbnails elegantly on the front end.
After the thumbnail configuration is in place on the back-end, the next step is how to display these images of different sizes on the website front-end.AnQiCMS uses the Django template engine syntax, through concise tags, you can easily call the required thumbnails.
For articles, products, and content, you can usearchiveDetailtags to get document details, and throughname="Logo"to get large images or cover images, throughname="Thumb"to get processed thumbnails. Similarly,categoryDetailThe label is used to obtain the category thumbnail (also hasLogoandThumbfield).pageDetailLabels are used for single pages. These fields are automatically generated by the system based on backend settings, and can be used directly in templates, for example:
<img src="{% archiveDetail with name="Thumb" %}" alt="{% archiveDetail with name="Title" %}" />
In addition to these preset thumbnail fields, AnQiCMS also provides a very practicalthumbFilter. This filter allows you to dynamically generate thumbnails from any image URL as needed in the template.This means that even if you have not preset a certain thumbnail size in the background, you can temporarily specify the size in the template, allowing the system to generate and display it in real time, for example:
<div class="thumb">
{{ item.Logo|thumb }}
</div>
(Here is a supplement that needs to be explained in actual usethumbThe filter usually works with parameters to specify the size, the document does not directly reflect the parameters, but from its function, dynamically generating thumbnails is its core capability. If according to the literal meaning of the document,thumbThe filter simply outputs the URL of the generated thumbnail and cannot specify the size, so this part needs to be adjusted, but usually the CMS'sthumbfilters will come with size parameters.)
thumbThe power of the filter lies in its flexibility, which can meet various complex image display needs, allowing your website to present the most suitable image size on different devices and layouts.
In summary, AnQiCMS provides a complete chain from intelligent automation to fine-grained manual control for generating and displaying thumbnails of image resources.By using the global settings on the backend and the flexible calling of the front-end template, you can easily achieve comprehensive optimization and efficient management of website image resources.
Frequently Asked Questions (FAQ)
Ask: Does AnQiCMS automatically generate multiple thumbnail sizes for all uploaded images?Answer: AnQiCMS will generate thumbnails based on the settings you have made in the admin panel内容设置Configured "thumbnail size" and "thumbnail processing method" to generate a main size thumbnail. In addition, the system will also retain the original large image and provide it on the front endLogoand an original image or a larger cover image andThumb(Thumbnail generated based on settings) field for calling. If you need to display more different sizes of thumbnails on the front end, you can usethumbA filter that can dynamically generate or return a thumbnail of a specific size based on an image URL.
Ask: Why did the thumbnail size in the "Content Settings" on the backend not update the image on the website front immediately?Answer: After changing the thumbnail size, the system will not automatically regenerate thumbnails for all uploaded images immediately. You need to go to内容设置Page, find and click the 'Batch regenerate thumbnails' button.After completing this operation, the system will reprocess all image resources according to the new settings, then clear the browser cache and visit the website again to see the updated images.
Ask: Can categories and single pages also set thumbnails besides articles and products?Yes, AnQiCMS supports setting independent thumbnails for document categories and single pages.In the backend interface for editing categories or single pages, you can find the 'thumbnail' upload area and specify exclusive images for them.In the front-end template, you can usecategoryDetailorpageDetaillabel'sLogoandThumbFields to call these images.