您好,登錄后才能下訂單哦!
本文提及Linux系統版本 CentOS7
MAC 系統重新安裝一下imagick?就好了,似乎等于更新了我之前的版本就有效了。
brew reinstall imagemagick
convert -list format | grep webp
Centos 安裝了Imagick但是不含webp, 參考前一篇安裝文章php 安裝imagick圖形處理庫
yum remove ImageMagick
wget https://www.imagemagick.org/download/ImageMagick.tar.gz
tar zxvf ImageMagick.tar.gz
?
cd ImageMagick-7.0.9-26/
?
./configure --with-webp
./libtool: line 1765: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
這個問題,客戶端導致的,別找服務器方案
MAC下設置下就好了
轉存失敗
重新上傳
取消
安裝webp
yum -y install libwebp-devel libwebp-tools
#php -m| grep imagick
?
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/imagick.so' - /usr/lib64/php/modules/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
報錯了
卸載之前安裝的
pecl uninstall imagick
再安裝一遍
pecl install imagick
php -m| grep imagick
好了
php --ri imagick
?
imagick
?
imagick module => enabled
imagick module version => 3.4.4
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version => ImageMagick 7.0.9-26 Q16 x86_64 2020-02-26 https://imagemagick.org
Imagick using ImageMagick library version => ImageMagick 7.0.9-26 Q16 x86_64 2020-02-26 https://imagemagick.org
ImageMagick copyright => ? 1999-2020 ImageMagick Studio LLC
ImageMagick release date => 2020-02-26
ImageMagick number of supported formats: => 239
ImageMagick supported formats => 3FR, 3G2, 3GP, A, AAI, AI, ART, ARW, AVI, AVS, B, BGR, BGRA, BGRO, BMP, BMP2, BMP3, BRF, C, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUBE, CUR, CUT, DATA, DCM, DCR, DCRAW, DCX, DDS, DFONT, DNG, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, FAX, FILE, FITS, FLV, FRACTAL, FTP, FTS, G, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, JNG, JNX, JPE, JPEG, JPG, JPS, JSON, K, K25, KDC, LABEL, M, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, O, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PS, PS2, PS3, PSB, PSD, PTIF, PWP, R, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGB565, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCREENSHOT, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TM2, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WMV, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, Y, YCbCr, YCbCrA, YUV
?
Directive => Local Value => Master Value
imagick.locale_fix => 0 => 0
imagick.skip_version_check => 0 => 0
imagick.progress_monitor => 0 => 0
header('Content-type: image/jpeg');
date_default_timezone_set("Asia/Shanghai");
$image = new Imagick('a.png');
$image->thumbnailImage(100, 0);
echo $image;
5.2 轉換,把png 改成jpg
<?php
?
date_default_timezone_set("Asia/Shanghai");
$thumb = new Imagick();
$thumb->readImage('a.png');
$thumb->writeImage('b.jpg');
$thumb->clear();
$thumb->destroy();
?>
5.3 轉換,把png 改成webp
<?php
?
date_default_timezone_set("Asia/Shanghai");
$thumb = new Imagick();
$thumb->readImage('a.png');
$thumb->writeImage('b.webp');
$thumb->clear();
$thumb->destroy();
?>
?
-rw-r--r-- 1 root root 33761 Feb 26 16:59 a.png
-rwxrwxrwx 1 root root 10158 Feb 26 16:50 a.webp
-rw-r--r-- 1 apache apache 46142 Feb 26 17:37 b.jpg
-rw-r--r-- 1 apache apache 10158 Feb 26 17:38 b.webp
-rwxrwxrwx 1 root root 172 Feb 26 17:38 webp.php
可以看到 b.webp的文件比b.jpg的文件小很多,說明成功的轉換了webp文件。
5.4 用一下setImageFormat 設置webp
當使用了setImageFormat才能看出來webp其實沒有安裝成功。
date_default_timezone_set("Asia/Shanghai");
$thumb = new Imagick();
$thumb->readImage('a.png');
$thumb->setImageFormat("webp");
$thumb->writeImage('b.webp');
$thumb->clear();
$thumb->destroy();
Fatal error: Uncaught exception 'ImagickException' with message 'Unable to set image format' in /www/webp.php:6 Stack trace: #0 /www/javaer.com/webp.php(6): Imagick->setimageformat('webp') #1 {main} thrown in /www/javaer.com/webp.php on line 6
./configure --with-webp=yes
make
make install
6.2 查看,更新webp
convert -list format | grep WebP
還是沒有
更新一下lib的綁定【很關鍵,我折騰了好幾遍,感覺就是差了這一步】
ldconfig /usr/local/lib
convert -list format | grep WebP
好了。
特別關鍵,在重裝以后要執行這句話。
ldconfig /usr/local/lib
6.2 看看php的插件是否支持webp
服務器上執行
php --ri imagick | grep WEBP
沒有
那么重新安裝php的imagick
pecl uninstall imagick
pecl install imagick
php --ri imagick | grep WEBP
有了
轉存失敗
重新上傳
取消
6.3 寫個test.php 看看phpinfo里有沒有
但是phpinfo()里沒有
重啟動fpm, 重啟動nginx
phpinfo也有了
轉存失敗
重新上傳
取消
當php使用了setImageFormat 設置webp的格式時候,就不會報錯了。徹底安裝成功。
webp官方
https://developers.google.com/speed/webp/download
https://java-er.com/blog/php-webp-imagick/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。