{"id":232782,"date":"2021-12-23T08:20:01","date_gmt":"2021-12-23T00:20:01","guid":{"rendered":"https:\/\/gulass.cn\/?p=232782"},"modified":"2021-12-22T16:20:59","modified_gmt":"2021-12-22T08:20:59","slug":"linux-imagemagick-operate","status":"publish","type":"post","link":"https:\/\/gulass.cn\/linux-imagemagick-operate.html","title":{"rendered":"\u5728 Linux \u4e2d\u4f7f\u7528ImageMagick\u547d\u4ee4\u884c\u64cd\u4f5c\u56fe\u50cf\u6587\u4ef6"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4f7f\u7528 convert \u547d\u4ee4\uff0c\u53ef\u4ee5\u65e0\u9700\u6253\u5f00\u56fe\u50cf\u7f16\u8f91\u5668\u8fdb\u884c\u4fee\u6539\u56fe\u50cf\u6587\u4ef6\u3002convert\u547d\u4ee4\u5305\u542b\u5728ImageMagick\u5b89\u88c5\u5305\u91cc\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
Centos8\u5b89\u88c5ImageMagick<\/strong><\/div>\n

ImageMagick \u53ef\u4ee5\u5b89\u88c5\u5728Linux\u3001Mac OS X\u3001Windows\u7cfb\u7edf\u4e2d\u3002\u4e0b\u8f7d\u94fe\u63a5\u4e3a\uff1a<\/p>\n

http:\/\/www.imagemagick.org\/script\/download.php<\/a><\/p>\n

\u4e0b\u9762\u5728Centos8\u4e2d\u5b89\u88c5ImageMagick\uff1a<\/p>\n

\r\n[root@localhost ~]# wget https:\/\/download.imagemagick.org\/ImageMagick\/download\/linux\/CentOS\/x86_64\/ImageMagick-7.1.0-17.x86_64.rpm\r\n[root@localhost ~]# wget https:\/\/download.imagemagick.org\/ImageMagick\/download\/linux\/CentOS\/x86_64\/ImageMagick-libs-7.1.0-17.x86_64.rpm\r\n<\/pre>\n

\u4e0b\u8f7d\u5230\u672c\u5730\u4e4b\u540e\uff0c\u4f7f\u7528yum\u547d\u4ee4\u5b89\u88c5\u8fd9\u4e24\u4e2a\u5305\uff1a<\/p>\n

\r\n[root@localhost ~]# yum localinstall ImageMagick-*\r\n<\/pre>\n

\"\"<\/p>\n

\u6309\u56fe\u50cf\u7c7b\u578b\u8f6c\u6362\u6587\u4ef6<\/strong><\/div>\n

\u4f7f\u7528 convert \u547d\u4ee4\u5c06\u56fe\u50cf\u4ece\u4e00\u79cd\u683c\u5f0f\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u683c\u5f0f\u975e\u5e38\u5bb9\u6613\u3002\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u6765\u8f6c\u6362\uff1a<\/p>\n

\r\n[root@localhost data]# convert penguins.jpg penguins.png\r\n<\/pre>\n

penguins.png \u56fe\u50cf\u5e94\u8be5\u4e0e\u539f\u59cb penguins.jpg \u6587\u4ef6\u770b\u8d77\u6765\u76f8\u540c\uff0c\u4f46\u8be5\u6587\u4ef6\u5c06\u5177\u6709\u6307\u5b9a\u7684\u6587\u4ef6\u6269\u5c55\u540d\u5e76\u4e14\u5927\u5c0f\u4e0d\u540c\u3002convert \u547d\u4ee4\u5c06\u4f7f\u7528\u4f60\u63d0\u4f9b\u7684\u6587\u4ef6\u540d\u6765\u786e\u5b9a\u6700\u7ec8\u60f3\u8981\u7684\u6587\u4ef6\u7c7b\u578b\u5e76\u76f8\u5e94\u5730\u4fee\u6539\u56fe\u50cf\u3002<\/p>\n

\u5982\u679c\u6000\u7591\u8f6c\u6362\u662f\u5426\u6709\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u968f\u65f6\u4f7f\u7528 od<\/code> \u547d\u4ee4\u68c0\u67e5\u6bcf\u4e2a\u6587\u4ef6\u7684\u5f00\u5934\u3002<\/p>\n

\r\n[root@localhost data]# od -bc penguins.jpg |head -6\r\n0000000 377 330 377 340 000 020 112 106 111 106 000 001 001 000 000 001\r\n        377 330 377 340  \\0 020   J   F   I   F  \\0 001 001  \\0  \\0 001\r\n0000020 000 001 000 000 377 333 000 103 000 002 001 001 001 001 001 002\r\n         \\0 001  \\0  \\0 377 333  \\0   C  \\0 002 001 001 001 001 001 002\r\n0000040 001 001 001 002 002 002 002 002 004 003 002 002 002 002 005 004\r\n        001 001 001 002 002 002 002 002 004 003 002 002 002 002 005 004\r\n[root@localhost data]# \r\n[root@localhost data]# \r\n[root@localhost data]# od -bc penguins.png |head -6\r\n0000000 211 120 116 107 015 012 032 012 000 000 000 015 111 110 104 122\r\n        211   P   N   G  \\r  \\n 032  \\n  \\0  \\0  \\0  \\r   I   H   D   R\r\n0000020 000 000 001 016 000 000 000 375 010 002 000 000 000 302 242 016\r\n         \\0  \\0 001 016  \\0  \\0  \\0 375  \\b 002  \\0  \\0  \\0 302 242 016\r\n0000040 361 000 000 000 004 147 101 115 101 000 000 261 217 013 374 141\r\n        361  \\0  \\0  \\0 004   g   A   M   A  \\0  \\0 261 217  \\v 374   a\r\n<\/pre>\n

\"\"
\n\u7b2c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u663e\u793a\u7684\u201cJFIF\u201d\u5b57\u7b26\u4e32\u548c\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u663e\u793a\u7684\u201cPNG\u201d\u9a8c\u8bc1\u64cd\u4f5c\u662f\u5426\u6309\u6307\u793a\u6267\u884c\u3002\u8fd9\u4e9b\u662f\u7528\u4e8e\u8bc6\u522b\u8fd9\u4e24\u79cd\u6587\u4ef6\u683c\u5f0f\u7684\u5185\u90e8\u4ee3\u7801\u3002<\/p>\n

\u91cd\u65b0\u683c\u5f0f\u5316\u5927\u91cf\u6587\u4ef6<\/strong><\/div>\n

\u5982\u679c\u60a8\u60f3\u4f7f\u7528 convert \u547d\u4ee4\u4ece\u6570\u767e\u4e2a .png \u6587\u4ef6\u751f\u6210\u6570\u767e\u4e2a .jpg \u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u811a\u672c\u3002\u6839\u636e\u8981\u8f6c\u6362\u7684\u6587\u4ef6\u6570\u91cf\uff0c\u5b8c\u6210\u4efb\u52a1\u53ef\u80fd\u53ea\u9700\u8981\u51e0\u79d2\u949f\u6216\u51e0\u5206\u949f\u7684\u65f6\u95f4\u3002<\/p>\n

\r\n[root@localhost test]# vim batch_convert.sh \r\n\r\n#!\/bin\/bash\r\n\r\nfor file in `ls *.jpg`\r\ndo      \r\n        newfile=`echo $file | sed 's\/jpg\/png\/'`\r\n        convert $file $newfile\r\ndone    \r\n<\/pre>\n

\"\"
\n\u8f6c\u6362\u4e4b\u524d\uff0c\u4e0b\u9762\u7684\u7167\u7247\u683c\u5f0f\u662fjpg\uff1a
\n\"\"
\n\u4e0b\u9762\u6267\u884c\u8be5\u811a\u672c\u6765\u4fee\u6539\u56fe\u7247\u683c\u5f0f\uff1a<\/p>\n

\r\n[root@localhost test]# .\/batch_convert.sh \r\n<\/pre>\n

\"\"<\/p>\n

\u65cb\u8f6c\u548c\u7ffb\u8f6c<\/strong><\/div>\n

\u8981\u65cb\u8f6c\u6587\u4ef6\uff0c\u9700\u8981\u5728convert\u547d\u4ee4\u4e2d\u8f93\u5165\u8981\u65cb\u8f6c\u591a\u5c11\u5ea6\u3002\u4e0b\u9762\u4e24\u4e2a\u547d\u4ee4\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5c06\u6309\u987a\u65f6\u9488\u65b9\u5411\u5c06\u56fe\u50cf\u65cb\u8f6c 45 \u5ea6\u3002\u7b2c\u4e8c\u4e2a\u4f7f\u7528 -flip \u9009\u9879\u5c06\u5176\u5782\u76f4\u7ffb\u8f6c\u3002<\/p>\n

\r\n[root@localhost data]# convert penguins.jpg -rotate 45 penguins_45.png\r\n[root@localhost data]# convert penguins.jpg -flip penguins_flip.png\r\n<\/pre>\n

\"\"
\n\u5782\u76f4\u65cb\u8f6c\u548c180\u5ea6\u65cb\u8f6c\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u53ef\u4ee5\u770b\u4e0b\u56fe\uff1a
\n\"\"<\/p>\n

\u9644\u52a0\u56fe\u7247<\/strong><\/div>\n

\u5728\u6b64\u547d\u4ee4\u4e2d\uff0c\u6211\u4eec\u5c06\u4e24\u4e2a\u56fe\u50cf\u9644\u52a0\u5728\u4e00\u8d77\u4ee5\u5f62\u6210\u5355\u4e2a\u56fe\u50cf\u3002<\/p>\n

\r\n[root@localhost data]# convert penguins.jpg penguins_flip.png -append append_pengius.png\r\n<\/pre>\n

\"\"
\n\u4f7f\u7528-append<\/code>\u9009\u9879\uff0c\u5c06\u4e24\u4e2a\u56fe\u7247\u4e0a\u4e0b\u5408\u5e76\u3002\u5982\u679c\u4f7f\u7528+append<\/code>\u9009\u9879\uff0c\u5c06\u4e24\u4e2a\u56fe\u7247\u5de6\u53f3\u5408\u5e76\uff1a<\/p>\n

\r\n[root@localhost data]# convert penguins.jpg penguins_flip.png +append append+pengius.png\r\n<\/pre>\n

\"\"<\/p>\n

\u8c03\u6574\u56fe\u50cf\u6bd4\u4f8b<\/strong><\/div>\n

\u53ef\u4ee5\u4f7f\u7528-resize<\/code>\u6765\u8c03\u6574\u6bd4\u4f8b\uff0c\u4e0b\u9762\u4e24\u6761\u547d\u4ee4\u662f\u5c06\u56fe\u7247\u7f29\u5c0f65%\uff0c\u548c\u653e\u5927\u5230150%\u3002<\/p>\n

\r\n[root@localhost data]# convert penguins.jpg -resize 65% pen_65.jpg\r\n[root@localhost data]# convert penguins.jpg -resize 150% pen_150.jpg\r\n<\/pre>\n

\"\"<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u4f7f\u7528 convert \u547d\u4ee4\uff0c\u53ef\u4ee5\u65e0\u9700\u6253\u5f00\u56fe\u50cf\u7f16\u8f91\u5668\u8fdb\u884c\u4fee\u6539\u56fe\u50cf\u6587\u4ef6\u3002convert\u547d\u4ee4\u5305\u542b\u5728ImageMagick\u5b89\u88c5\u5305\u91cc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

ImageMagick \u53ef\u4ee5\u5b89\u88c5\u5728Linux\u3001Mac OS X\u3001Windows\u7cfb\u7edf\u4e2d\u3002\u4e0b\u8f7d\u94fe\u63a5\u4e3a\uff1a http: […]<\/p>\n","protected":false},"author":309,"featured_media":232783,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-232782","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/232782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=232782"}],"version-history":[{"count":5,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/232782\/revisions"}],"predecessor-version":[{"id":232798,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/232782\/revisions\/232798"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/232783"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=232782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=232782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=232782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}