[英]How can I compress images,so that google pagespeed test won't recommend to compress that image again?
Whenever I run pagespeed test , it gives possible optimization of images in bytes & percentage like, 每当我运行pagespeed test时,它都会以字节和百分比的形式提供图像的可能优化,例如,
Compressing and resizing https://example.com/ …ts/AMP.jpg?6750368613317441460 could save 530KiB (91% reduction). 压缩并调整大小https://example.com/…ts / AMP.jpg?6750368613317441460可以节省530KiB(减少91%)。
Compressing https://example.com/ …AMP.png?12287830358450898504 could save 4.4KiB (31% reduction). 压缩https://example.com/…AMP.png?12287830358450898504可以节省4.4KiB(减少31%)。
I am using ImageMagick to compress the images. 我正在使用ImageMagick压缩图像。
I have tried convert AMP.gif_or_png -strip [-alpha Remove] OUTPUT.png
for png images and 我已经尝试
convert AMP.gif_or_png -strip [-alpha Remove] OUTPUT.png
为png图像,
convert INPUT.jpg -sampling-factor 4:2:0 -strip [-quality 85] [-interlace JPEG] [-colorspace RGB] OUTPUT.jpg
for jpg images, but none of the above commands gives me the same reduction as suggested by google pagespeed. 对于jpg图像,但上述命令均不能像google pagespeed那样为我提供相同的降低效果。 So, let me know if i am missing any parameters or I have passed wrong values of parameters.
所以,让我知道我是否缺少任何参数,或者我传递了错误的参数值。
The pack of compressed contents are available on google pagespeed page but,I want to compress images using ImageMagick or any other sources . 压缩内容包可在google pagespeed页面上找到,但是,我想使用ImageMagick或任何其他来源来压缩图像。
If you are looking for a commercial tool, JPEGmini can be used. 如果您正在寻找商用工具, 则可以使用JPEGmini 。 You can also use imagemin if you are going to use Grunt task runner.
如果要使用Grunt任务运行程序,也可以使用imagemin 。 You can also use command lines tools that are provided with imagemin such as jpeg-tran and opti-png , and they are open source as well.
您还可以使用imagemin附带的命令行工具,例如jpeg-tran和opti -png ,它们也是开源的。
可能是没有可用的工具来动态地执行任务。您应该进行一些计算,或者如果您使用任何语言来执行任务,那么就会有很多内置的类可用,因此您可以使用这些类来压缩图像,例如在Java Imagescalr中,Thumbnail或ImageWriteParam,或者您也可以使用Matlab。
Compressing and resizing https://example.com/ …ts/AMP.jpg?6750368613317441460 could save 530KiB (91% reduction).
压缩并调整大小https://example.com/…ts / AMP.jpg?6750368613317441460可以节省530KiB(减少91%)。
530 KiB reduction is quite a lot. 530 KiB减少很多。 Verify that the image size is congruous.
验证图像大小是否一致。 I mean, if you have a 400x200 image and you show it at 200x100, then serving it at the correct resolution (or resolutions) could be what PageSpeed is after.
我的意思是,如果您有一个400x200的图片,并且以200x100的比例显示,那么PageSpeed所追求的就是以正确的分辨率(或多个分辨率)进行投放。
For PNG images, often color reduction is possible: if you have a 12 colors image (eg a schematic), having it in 24-bit, 8-bit or 4-bit format makes a significant difference, while changing nothing in what people see once it's displayed. 对于PNG图像,通常可以减少颜色:如果您有12色图像(例如原理图),则以24位,8位或4位格式显示图像会有很大的不同,而人们所看到的却没有任何改变一旦显示出来。 Good call removing unneeded alpha channel, though.
不过,移除不必要的Alpha通道的通话效果不错。
The rest you can do with tools like pngopt
, pngcrush
or advpng
. 其余的您可以使用
pngopt
, pngcrush
或advpng
类的工具advpng
。 JPEG quality parameter or suitable tools ( tinyjpg , or google 'JPEG compression optimizer') can be used to improve JPEG size. 可以使用JPEG质量参数或合适的工具( tinyjpg或google'JPEG压缩优化器')来提高JPEG大小。 There are some tools that are capable of selectively encoding different areas of the image, or rewrite a PNG palette to leverage zLib compression features.
有一些工具能够选择性地编码图像的不同区域,或重写PNG调色板以利用zLib压缩功能。
Another possibility with JPEG is using the progressive format, that allows quickly displaying a raw image, and refine it iteratively. JPEG的另一种可能性是使用逐行格式,该格式允许快速显示原始图像并对其进行迭代优化。 More overall bandwidth but also more apparent speed (less browser support also; check it out).
更多的总带宽也更明显的速度(以下浏览器支持也;检查出来)。
It is not automatic that any of this can be done with ImageMagick - after all, ImageMagick is not directly tasked with file manipulation but with image manipulation. 使用ImageMagick可以自动完成所有这些操作不是自动的-毕竟,ImageMagick并不直接负责文件操作,而是直接负责图像操作。 It may well be that its file-compression functions are not as complete or as advanced as other tools'.
它的文件压缩功能可能不如其他工具那么完善或先进。
您可以从该页面下载压缩包,其中包含图像和针对其喜好而优化的代码...这几乎是最好的图像压缩。
I would recommend thumbor.org . 我会推荐thumbor.org 。 It's a open source imaging service which you can simply start using a docker container on Amazon Elastic Beanstalk.
这是一个开源映像服务,您可以简单地开始在Amazon Elastic Beanstalk上使用docker容器。 It has some pretty nice features like smart cropping and face detection.
它具有一些不错的功能,例如智能裁剪和面部检测。
To start it, just create a elastic beanstalk environment with docker as predefined configuration. 要启动它,只需使用docker作为预定义配置创建一个弹性beantalk环境。 Then you provide a JSON-File with following content in the application version tab.
然后,在“应用程序版本”选项卡中提供具有以下内容的JSON文件。
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "apsl/thumbor"
},
"Ports": [
{
"ContainerPort": "8000"
}
]
}
You can then configure thumbor with elastic beanstalk environment variables. 然后,可以使用弹性beantalk环境变量配置thumbor。 For optimizing JPG you should add the jpegtran optimizer.
为了优化JPG,您应该添加jpegtran优化器。
OPTIMIZERS=['thumbor.optimizers.jpegtran'] OPTIMIZERS = ['thumbor.optimizers.jpegtran']
We use it at Storyblok.com to optimize the images and Google Pagespeed is happy with the result: https://www.storyblok.com/docs/Guides/how-to-resize-images 我们在Storyblok.com上使用它来优化图像,而Google Pagespeed对结果感到满意: https ://www.storyblok.com/docs/Guides/how-to-resize-images
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.