How to use image compression to reduce COS traffic costs?

Introduction

This article will introduce how to use COS to reduce costs and increase efficiency through the [Image Compression] capability. The article will be written in an easy-to-understand manner, aiming to quickly guide users to understand the usage and benefits of image compression.

Why does image compression reduce costs and increase efficiency?

With the continuous expansion of Internet traffic, the downstream outbound traffic of object storage COS has increased rapidly, especially the most critical part of the Web (picture business). Due to the synchronous loading feature of HTML, it is usually loaded only after a page next one.

Using the image compression capability will reduce the size of your image, and the reduced image will occupy less bandwidth and consume less traffic when transmitted on the network, thereby reducing your traffic bandwidth cost. At the same time, the reduced size of the picture takes less time to transmit on the network, thereby increasing the speed at which your client loads pictures.

Preparations for using image compression

The image compression service is provided by Tencent Cloud Data Vientiane products. You can enable the image compression service by following the steps below:

Step 1: Open Data Vientiane product

In the Tencent Cloud console, select Cloud Products > Vientiane Data, enter the Vientiane Data console, and activate the Vientiane Data service.

【Operation link】: https://console.cloud.tencent.com/ci

Step 2: Bind Data Vientiane with the storage bucket where you store pictures

[Operation link]: https://console.cloud.tencent.com/ci/bucket

►►►

Step 3: Turn on the image advanced compression service

In the Object Storage console, select the bucket bound to Data Vientiane, go to the Data Processing > Image Processing menu, and enable advanced compression.

Get started quickly

From 0 to 1, it will take you to quickly learn how to use image compression, and quickly reduce the cost of your image business in 1 minute! Image compression supports use through URL parameters, API, SDK, etc.

1. Upload pictures to COS

1. Enter the file list in the storage bucket that has enabled advanced image compression

2. Select Upload File > Select File, and select the image to be uploaded to the storage bucket, for example, an image named exampleimage.png.

3. Click Upload to upload the image exampleimage.png to the storage bucket.

2. Normal access to pictures on COS

1. Find the exampleimage.png image just uploaded in the console file list, and click the details in the operation bar

2. Copy the address of the object and open the address in a new window of the browser to access the picture.

> > note

If you see the error message "Access Denied" when you open the image, it means that the image has private read access permission, and you need to carry the signature parameter after the object address to access it normally.

In the details, you can quickly obtain an object address with a signature by copying the temporary link.

It can be seen that the size of the exampleimage.png image accessed by the browser is 1.7MB of the original image, and the overall image loading time is 3.24 seconds

3. Use image compression and access the compressed image

Take compressing pictures into avif format as an example:

After the object address in step 3.2, directly add an AVIF image compression parameter, and connect the parameters through the ? symbol: ?imageMogr2/format/avif

>> attention

If the above link already carries signature parameters, you can also directly add the AVIF image compression parameters after the link, and use the & symbol to connect the parameters: &imageMogr2/format/avif

It can be seen that the exampleimage.png image will be compressed in real time after carrying the compression parameters. The size of the compressed image accessed by the browser is 75.5KB, and the overall image loading time is 287 milliseconds.

Using Image Compression via API

You can access the object interface GET Object through COS to directly use the image compression capability.

1. Call the GET Object interface

2. Add image compression parameters directly after the <ObjectKey> parameter in the interface, and connect them through the ? symbol.

[GET Object interface document]: https://cloud.tencent.com/document/product/436/7753

[Image compression parameter document]: https://cloud.tencent.com/document/product/436/44883

>> attention

图片压缩是通过格式转换参数控制的,您可以将图片转换为webp、avif、heif、tpg这四种压缩格式,来达到图片体积减少的目的。

通过 SDK 使用图片压缩

当前图片压缩参数已经集成到了所有的 COS SDK 中,提供 Java、Python 等12种开发语言的 SDK 及对应的快速入门指引,您可以点击下方链接找到适合自己的SDK:

【SDK链接】:https://cloud.tencent.com/document/product/436/6474

不同压缩图片格式对比

不同的压缩格式各有优劣,您可以按需选择

购买指南

图片压缩支持预付费和后付费,费用是由数据万象 CI 收取的。实际费用取决于您使用图片压缩的请求次数。

【图片压缩的计费详情】:https://cloud.tencent.com/document/product/436/58963

结语

图片压缩可以应用的场景很多,只要涉及到图片的业务,都可以使用来降低图片访问过程中产生的流量,提升图片在终端加载的速度。除了图片压缩以外,数据万象还提供诸如图片增强、视频压缩等实用功能,将在后续一一推出使用指南,敬请期待!

Guess you like

Origin blog.csdn.net/Tencent_COS/article/details/129749909