If you have a blog or a website with a lot of content sometimes the images can take a toll on the load time of the pages.如果你有一個博客或網站的內容很多,有時圖像可以採取收費的加載時間的網頁。 There are a number of steps you can take to speed things up.有一個數字的步驟,您可以採取加快速度。 If you analyze the loading of your website you might notice that the images take up a huge part of the load time.如果您分析您網站的加載您可能會注意到,影像是一個龐大的一部分加載時間。 Let's take a look at how you can compress your .png images to improve on this figure.讓我們來看看如何可以壓縮您的。PNG圖像,以改善這個數字。
We'll use the tool pngcrush for this purpose. pngcrush is a free and open source command line tool that, as the name suggests, compresses PNG images.我們將使用工具pngcrush用於這一目的。pngcrush是一個自由和開放源碼命令行工具,顧名思義,壓縮PNG圖像。 Take a look at the projects看一看在項目 website網站 for detailed information on how to use it.的詳細情況如何使用它。 We will cover the basics in this article.我們將介紹基本的這篇文章。
Installation安裝
Most modern distributions of Linux such as Fedora and Ubuntu have pngcrush available directly in their default repositories.大多數現代的Linux發行版,如Fedora和Ubuntu有pngcrush可直接在其默認庫。 So, to install it on you Ubuntu computer execute the following command:因此,要安裝在您Ubuntu計算機執行以下命令:
# sudo apt-get install pngcrush #sudo易於得到安裝pngcrush
On Fedora do the following:在Fedora執行下列操作:
# yum install pngcrush #yum安裝pngcrush
Usage用法
pngcrush optimizes a PNG graphics file by reducing the size of the files IDAT chunk. pngcrush優化了PNG圖形文件的大小減少了文件的IDAT塊。 The process is not simple.這個過程並不簡單。 The great thing about pngcrush is that the authors of the tool have simplified things for you.最偉大的一方面pngcrush是,作者的工具,已經簡化了的東西你。 They ship it with a great option – brute .這些船舶它與一個偉大的選擇- 野蠻 。 When you use this option you effectively tell pngcrush to try and use the most suitable method to compress the image at hand.當您使用此選項,您可以有效地告訴pngcrush嘗試使用最適當的方法來壓縮圖像在眼前。 There are about 114 different filters that can be used, so this option is mighty useful.大約有114個不同的過濾器,可使用,所以這個選項,浩浩蕩盪有益的。 Here's how you would use it to compress an image:這裡你將如何使用它來壓縮圖像:
# pngcrush -brute -e “.compressed.png” image01.png #pngcrush -蠻力- e“的。compressed.png”image01.png
The two options used here are -brute which I just explained, and -e .兩個方案用在這裡是,野蠻的 ,我剛才解釋,和- e。 The second option tells pngcrush what extension to add the the filenames.第二個選項告訴pngcrush什麼擴展來添加的文件名。 So after the process of crushing is complete the compressed version of the file image01.png will be called image01.compressed.png .所以在這個過程完成粉碎的壓縮版本文件image01.png將調用image01.compressed.png。 you can change the extension if you like.您可以更改擴展名,如果你喜歡。
You can also slightly modify the above command to compress several PNG files in a directory.您還可以稍微修改上面的命令來壓縮多個PNG文件的目錄。 Execute the following command:執行以下命令:
# pngcrush -brute -d “/var/www/html/website/images/” *.png #pngcrush -蠻力- D“類/無功/ www / html等/網站/圖片/”*.巴新
The above command uses a new option, -d .上面的命令使用一個新的選擇, 三維 。 This option tells pngcrush where to place the compressed image files after the compression is complete.這個選項告訴pngcrush放置壓縮的圖像文件壓縮後完成。 The above command will compress all the PNG file in the current directory and place them in /var/www/html/website/images/ .上面的命令將所有的壓縮PNG文件在當前目錄,並把他們在/ var / www / html等/網站/圖像/。
I strongly suggest that you read up more about this tool and its options on the projects website.我強烈建議您閱讀更多有關此工具及其選擇的項目網站。 There are a lot of options that might help you speed up the process of compression or do a better job of it.有很多的選項可以幫助您加快進程壓縮或做得更好它。 Put the new images into your website and watch your pages load faster.把新的圖像到您的網站,看你的網頁的速度更快。























0 Responses 0回應
Stay in touch with the conversation, subscribe to the保持接觸與對話,訂閱 RSS feed for comments on this post RSS飼料評論對這個職位 . 。