Để cài đặt Php ImageMagick trên Centos 7
ImageMagick là một bộ phần mềm nguồn mở và miễn phí được sử dụng để tạo, chỉnh sửa, sáng tác hoặc chuyển đổi hình ảnh bitmap. Với Imagemagick, bạn có thể dễ dàng đọc và viết hình ảnh theo nhiều định dạng như GIF, JPEG, PNG, PostScript và TIFF. Bạn cũng có thể sử dụng ImageMagick để thay đổi kích thước, lật, gương, xoay, biến dạng, cắt và biến đổi hình ảnh và nhiều hơn nữa. Thật sự rất dễ dàng để cài đặt Imagemagic và trong hướng dẫn này, bạn sẽ tìm hiểu về phương pháp để cài đặt nó trên Centos 7.
Cài đặt ImageMagick
Việc cài đặt ImageMagick yêu cầu một số công cụ phát triển nhất định và để thêm chúng vào hệ thống của bạn, bạn cần chạy lệnh sau, cài đặt tất cả chúng lại với nhau.
[[email protected] ~]# yum groupinstall " Development Tools" -y
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
There is no installed groups file.
Maybe run: yum groups mark convert [see man yum]
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
[1/4]: base/7/x86_64/group_gz | 156 kB 00:01
[2/4]: extras/7/x86_64/primary_db | 129 kB 00:01
[3/4]: base/7/x86_64/primary_db | 5.7 MB 00:23
[4/4]: updates/7/x86_64/primary_db | 3.6 MB 00:29
Loading mirror speeds from cached hostfile
* base: centos.myfahim.com
* extras: mirrors.viethosting.com
* updates: mirrors.vonline.vn
.
.
.
Dependency Updated:
boost-system.x86_64 0:1.53.0-27.el7 dyninst.x86_64 0:9.3.1-1.el7
gettext.x86_64 0:0.19.8.1-2.el7 gettext-libs.x86_64 0:0.19.8.1-2.el7
glibc.x86_64 0:2.17-196.el7 glibc-common.x86_64 0:2.17-196.el7
libgcc.x86_64 0:4.8.5-16.el7 libgomp.x86_64 0:4.8.5-16.el7
libstdc++.x86_64 0:4.8.5-16.el7 rpm.x86_64 0:4.11.3-25.el7
rpm-build-libs.x86_64 0:4.11.3-25.el7 rpm-libs.x86_64 0:4.11.3-25.el7
rpm-python.x86_64 0:4.11.3-25.el7 systemtap-runtime.x86_64 0:3.1-3.el7
Complete!
Khi các công cụ phát triển được cài đặt, bạn có thể bắt đầu cài đặt ImageMagick bằng cách chạy lệnh sau.
[[email protected] ~]# yum install ImageMagick ImageMagick-devel -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.myfahim.com
* extras: mirrors.viethosting.com
* updates: mirrors.vonline.vn
Resolving Dependencies
--> Running transaction check
---> Package ImageMagick.x86_64 0:6.7.8.9-15.el7_2 will be installed
--> Processing Dependency: libwmflite-0.2.so.7[][64bit] for package: ImageMagick-6.7.8.9-15.el7_2.x86_64
--> Processing Dependency: libImath.so.6[][64bit] for package: ImageMagick-6.7.8.9-15.el7_2.x86_64
.
.
.
.
libX11.x86_64 0:1.6.5-1.el7
libX11-common.noarch 0:1.6.5-1.el7
libXext.x86_64 0:1.3.3-3.el7
libXt.x86_64 0:1.1.5-3.el7
libtiff.x86_64 0:4.0.3-27.el7_3
libxcb.x86_64 0:1.12-1.el7
zlib.x86_64 0:1.2.7-17.el7
Complete!
Ngoài ra, bạn cần phải cài đặt tiện ích mở rộng Pear Php, vì vậy hãy chạy lệnh sau.
[[email protected] ~]# yum install php-pear
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.nhanhoa.com
* extras: mirrors.nhanhoa.com
* updates: centos-hn.viettelidc.com.vn
Resolving Dependencies
--> Running transaction check
---> Package php-pear.noarch 1:1.9.4-21.el7 will be installed
--> Processing Dependency: php-zlib for package: 1:php-pear-1.9.4-21.el7.noarch
--> Processing Dependency: php-xml for package: 1:php-pear-1.9.4-21.el7.noarch
--> Processing Dependency: php-tokenizer for package: 1:php-pear-1.9.4-21.el7.noarch
--> Processing Dependency: php-posix for package: 1:php-pear-1.9.4-21.el7.noarch
--> Processing Dependency: php-pcre for package: 1:php-pear-1.9.4-21.el7.noarch
--> Processing Dependency: php-ftp for package: 1:php-pear-1.9.4-21.el7.noarch
--> Processing Dependency: php-cli for package: 1:php-pear-1.9.4-21.el7.noarch
--> Processing Dependency: php-bz2 for package: 1:php-pear-1.9.4-21.el7.noarch
.
.
.
.
.
Installing : php-process-5.4.16-42.el7.x86_64 5/6
Installing : 1:php-pear-1.9.4-21.el7.noarch 6/6
Verifying : php-cli-5.4.16-42.el7.x86_64 1/6
Verifying : php-xml-5.4.16-42.el7.x86_64 2/6
Verifying : libzip-0.10.1-8.el7.x86_64 3/6
Verifying : php-process-5.4.16-42.el7.x86_64 4/6
Verifying : php-common-5.4.16-42.el7.x86_64 5/6
Verifying : 1:php-pear-1.9.4-21.el7.noarch 6/6
Installed:
php-pear.noarch 1:1.9.4-21.el7
Dependency Installed:
libzip.x86_64 0:0.10.1-8.el7 php-cli.x86_64 0:5.4.16-42.el7
php-common.x86_64 0:5.4.16-42.el7 php-process.x86_64 0:5.4.16-42.el7
php-xml.x86_64 0:5.4.16-42.el7
Complete!
Bạn cũng nên cài đặt tiện ích mở rộng PHP-Devel, có thể được thực hiện với sự trợ giúp của lệnh sau.
[[email protected] ~]# yum install php-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.nhanhoa.com
* extras: mirrors.nhanhoa.com
* updates: mirror.vbctv.in
Resolving Dependencies
--> Running transaction check
---> Package php-devel.x86_64 0:5.4.16-42.el7 will be installed
--> Processing Dependency: pcre-devel[x86-64] for package: php-devel-5.4.16-42.el7.x86_64
--> Running transaction check
---> Package pcre-devel.x86_64 0:8.32-17.el7 will be installed
--> Processing Dependency: pcre[x86-64] = 8.32-17.el7 for package: pcre-devel-8.32-17.el7.x86_64
--> Running transaction check
.
.
.
.
Verifying : pcre-devel-8.32-17.el7.x86_64 3/4
Verifying : pcre-8.32-12.el7.x86_64 4/4
Installed:
php-devel.x86_64 0:5.4.16-42.el7
Dependency Installed:
pcre-devel.x86_64 0:8.32-17.el7
Dependency Updated:
pcre.x86_64 0:8.32-17.el7
Complete!
Bây giờ bạn nên cài đặt ImageMagick bằng lệnh PECL.
[[email protected] ~]# pecl install Imagick
downloading imagick-3.4.3.tgz ...
Starting to download imagick-3.4.3.tgz [245,410 bytes]
...................................................done: 245,410 bytes
19 source files, building
running: phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
Please provide the prefix of Imagemagick installation [autodetect] :
building in /var/tmp/pear-build-rootwYkDqq/imagick-3.4.3
running: /var/tmp/imagick/configure --with-imagick
.
.
.
.
Build process completed successfully
Installing ' /usr/lib64/php/modules/imagick.so'
Installing ' /usr/include/php/ext/imagick/php_imagick_shared.h'
install ok: channel://pecl.php.net/imagick-3.4.3
configuration option " php_ini" is not set to php.ini location
You should add " /" to php.ini
Nó không vượt qua điều này, bạn cũng nên thêm Extension = Imagick.so trong VIM /ETC/PHP.INI, có thể được thực hiện với sự trợ giúp của lệnh sau.
[[email protected] ~]# vim /etc/php.ini extension=imagick.so [[email protected] ~]# php -i | grep Imagick imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator Imagick compiled with ImageMagick version => ImageMagick 6.7.8-9 2016-06-16 Q16 //www.imagemagick.org Imagick using ImageMagick library version => ImageMagick 6.7.8-9 2016-06-16 Q16 //www.imagemagick.org
ImageMagick đã được cài đặt. Bây giờ bạn có thể kiểm tra chức năng của ImageMagik mới được cài đặt. Phân tán hình ảnh bạn muốn chuyển đổi.
[[email protected] Downloads]#display
Hình ảnh của ImageMagick được hiển thị trên màn hình của bạn.
Bây giờ, hãy vào thư mục và bắt đầu chuyển đổi với sự trợ giúp của các lệnh được tô sáng dưới đây.
[[email protected] ~]# cd /root/Downloads/ [[email protected] Downloads]# ll total 20 -rw-r--r-- 1 root root 16473 Nov 2 11:26 relax.jpg [[email protected] Downloads]# display relax.jpg
Hình ảnh sẽ được chuyển đổi được hiển thị trên màn hình của bạn.
Bây giờ bạn có thể chuyển đổi định dạng của hình ảnh.
[[email protected] Downloads]# convert relax.jpg relax.png
Khi quá trình chuyển đổi được thực hiện, bạn có thể kiểm tra xem việc chuyển đổi có diễn ra không.
[[email protected] Downloads]# ll
total 340
-rw-r--r-- 1 root root 16473 Nov 2 11:26 relax.jpg
-rw-r--r-- 1 root root 326026 Nov 2 11:41 relax.png
Ngoài ra, bạn có thể kiểm tra thông tin hình ảnh để làm rõ thêm.
[[email protected] ~]# yum install ImageMagick ImageMagick-devel -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.myfahim.com
* extras: mirrors.viethosting.com
* updates: mirrors.vonline.vn
Resolving Dependencies
--> Running transaction check
---> Package ImageMagick.x86_64 0:6.7.8.9-15.el7_2 will be installed
--> Processing Dependency: libwmflite-0.2.so.7[][64bit] for package: ImageMagick-6.7.8.9-15.el7_2.x86_64
--> Processing Dependency: libImath.so.6[][64bit] for package: ImageMagick-6.7.8.9-15.el7_2.x86_64
.
.
.
.
libX11.x86_64 0:1.6.5-1.el7
libX11-common.noarch 0:1.6.5-1.el7
libXext.x86_64 0:1.3.3-3.el7
libXt.x86_64 0:1.1.5-3.el7
libtiff.x86_64 0:4.0.3-27.el7_3
libxcb.x86_64 0:1.12-1.el7
zlib.x86_64 0:1.2.7-17.el7
Complete!
0Do đó, kết thúc quá trình cài đặt của ImageMagik và phương pháp để che giấu hình ảnh từ định dạng này sang định dạng khác.