Centos8 generates webp thumbnails, installs ImageMagick and compresses pictures

ImageMagick is a software used to create, edit, and synthesize images. It can read, convert, and write images in multiple formats.

Functions include: image cutting, color replacement, application of various effects, image rotation, mirroring, writing text to images, etc.

1. The role of ImageMagick:

It is a software used to create, edit and synthesize pictures. It can read, convert and write pictures in various formats.

Functions include: image cutting, color replacement, application of various effects, image rotation, mirroring, writing text to images, etc.

Second, install ImageMagick with yum:

1. Install ImageMagick with yum

[root@uzbox]# yum install ImageMagick

Note: Please note that both I and M in the software package name are capitalized.

2. Check whether the software is installed successfully?

[root@uzbox ~]# whereis convert
convert: /usr/bin/convert /usr/share/man/man1/convert.1.gz

3. View the currently installed ImageMagick version and help

1. Check the version

[root@uzbox ~]# convert -version
Version: ImageMagick 6.9.10-86 Q16 x86_64 2020-01-13 https://imagemagick.org
Copyright: © 1999-2020 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP(4.5)
Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib gvc jbig jng jp2 jpeg
lcms ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib

2. View help

[root@uzbox ~]# convert --help

3. Check the manual

[root@uzbox ~]# man ImageMagick

Fourth, check the features supported by imagemagick:

1. List all formats supported by imagemagick:

[root@uzbox ~]# convert -list format

2. Check whether the current imagemagick version supports

[root@uzbox conf.d]# convert -list format | grep -i webp
WEBP* WEBP rw+ WebP Image Format (libwebp 1.0.0 [020E])

3. Display all available fonts:

[root@uzbox ~]$ convert -list font

4. Display all color channel types

[root@uzbox ~]$ convert -list channel

5. Display all color spaces

[root@uzbox ~]$ convert -list colorspace

6. Display all pixel compression types

[root@uzbox ~]$ convert -list compress

7. Display all color names

[root@uzbox ~]$ convert -list color

8. Show all filters

[root@uzbox ~]$ convert -list filter

Five, one of the most commonly used examples, generating webp thumbnails:

Generate webp thumbnails for images for website use:

1. If the original image is too large to be displayed directly on the website page,

   Not only does it waste server traffic, but it also takes a lot of time for users to open it.

   So generate thumbnails.

   Thumbnails for web use can be either jpg or webp

   We generate two thumbnails and compare their sizes

2. Download a wallpaper and use it as a test image

[root@uzbox ~]# wget https://uzbox.com/wp-content/uploads/2021/01/2021012209524593.jpg

Check the size of this image

[root@uzbox ~]# ll -h 2021012209524593.jpg
-rw-r--r-- 1 root root 136K January 22 17:52 2021012209524593.jpg

Check out the width and height of this image:

[root@uzbox ~]# file 2021012209524593.jpg
2021012209524593.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 96x96, segment length 16, baseline, precision 8, 1680x1050, frames 3

3. Generate jpg thumbnail

#-resize width x height (scale, no deformation), because both values are 500px, the larger value of width and height will be 500

#+profile '*' : remove metadata information, thumbnails do not need to save these contents

#-quality 90 : Specifies the quality of the image. The higher the quality, the more space it takes up. The maximum value is 100

# Generally, the difference between 85-90 and 100 is not noticeable to the naked eye, but the file size can be reduced more


[root@uzbox ~]# convert -resize 500x500 +profile '*' -quality 90 2021012209524593.jpg 2021012209524593tmb.jpg
[root@uzbox ~]# file 2021012209524593tmb.jpg
2021012209524593tmb.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 96x96, segment length 16, baseline, precision 8, 500x313, frames 3
[root@uzbox ~]# ll -h 2021012209524593tmb.jpg
-rw-r--r-- 1 root root 38K January 22 18:00 2021012209524593tmb.jpg

4. Generate webp thumbnail

[root@uzbox ~]# convert -resize 500x500 +profile '*' -quality 90 2021012209524593.jpg 2021012209524593tmb.webp
[root@uzbox ~]# file 2021012209524593tmb.webp
2021012209524593tmb.webp: RIFF (little-endian) data, Web/P image, VP8 encoding, 500x313, Scaling: [none]x[none], YUV color, decoders should clamp
[root@uzbox ~]# ll -h 2021012209524593tmb.webp
-rw-r--r-- 1 root root 29K January 22 18:02 2021012209524593tmb.webp

5. View the effect from the browser

Take a look at the screenshots:

Jpg format:

webp format:

6. Conclusion: There is no visible difference in the image quality between webp and jpg with the naked eye, but the file size is reduced by about 40%, so it is worth using.

6. Imagemagick related knowledge:

Imagemagick profile: records some descriptive information of the image, such as camera information (aperture, camera model), photoshop metadata, color table, etc.

Note: In some cases, the image description information may contain a large amount of data.

include:

exif: The camera records information such as aperture, manufacturer, model, resolution, and shooting time in the photo during the shooting process

iptc: IPTC metadata is a standard format that adds metadata to photo information, including: author, copyright, subtitles, detailed description, etc.

photoshop metadata: The metadata that photoshop writes to the image, in XML format

Photoshop calls it XMP metadata

7. Check the centos version:

[root@blog ~]$ cat /etc/redhat-release
CentOS Linux release 8.3.2011

1/5 - (1 vote)

Leave a Reply

Your email address will not be published. Required fields are marked *