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饲料对这个职位的评论 . 。