微信小程序选择图片优化

This article was sponsored by Cloudinary. Thank you for supporting the partners who make SitePoint possible.

本文由Cloudinary赞助。 感谢您支持使SitePoint成为可能的合作伙伴。

When adding images to a website, most of us will instinctively know to avoid using a GIF for a photo and avoid using a JPEG for a graph. The lazy ones among us – i.e., me – may just opt for PNG for everything and hope for the best.

当将图像添加到网站时,我们大多数人会本能地知道要避免对照片使用GIF,而对图形不使用JPEG。 我们中间那些懒惰的人(即我)可能只是为所有内容选择PNG,并希望做到最好。

So why do we do this? It all comes down to the encoding used to create the image in a particular file format. JPEG suits photography (the “P” stands for “Photographic”) since it blurs sharp edges but preserves smooth gradients. Encoding an image with large, sharply-defined blocks of color using JPEG causes loss of definition and inefficient encoding.

那么为什么我们要这样做呢? 全部归结为用于以特定文件格式创建图像的编码。 JPEG适合摄影(“ P”代表“摄影”),因为它模糊了锐利的边缘但保留了平滑的渐变。 使用JPEG对带有大尺寸,清晰定义的颜色块的图像进行编码会导致清晰度下降和编码效率低下。

Conversely, GIF suits logos or simple block graphs, since it focuses on the changes between uniform regions of color. This is obviously pretty useless for photos, where the colors differ almost pixel by pixel.

相反,GIF适合徽标或简单的方框图,因为它着重于颜色均匀区域之间的变化 。 对于颜色几乎逐个像素变化的照片,这显然是毫无用处的。

As an example, this image comes in at 106Kb as a JPEG:

举例来说,此图片以JPEG格式传入时106Kb

However, it reaches a whopping 517Kb encoded as a GIF. That’s almost 5 times bigger just by using an inappropriate image format. Oh dear.

但是,它达到了编码为GIF的高达517Kb 。 仅使用不适当的图像格式,它的大小几乎原来的5倍 。 噢亲爱的。

It manages to hit 329kb encoded as a PNG. Although not quite as bad, this is still over 3 times bigger than when using the most appropriate format for the image contents.

它设法达到329kb编码为PNG的格式。 尽管还不算太糟,但它仍比使用最合适的图像内容格式大3倍以上。

As we can easily see here, the main image formats are best suited to different types of content and choosing the wrong format for the image causes potentially significant, unnecessary bloat.

正如我们在此处可以轻松看到的那样,主要图像格式最适合于不同类型的内容,并且为图像选择错误的格式会导致潜在的显着不必要的膨胀。

You have to make sure that each image going on to your website is encoded in the most appropriate format, and not just the format in which you received it, in order to avoid unnecessary page bloat.

为了避免不必要的页面膨胀,您必须确保进入网站的每个图像都以最合适的格式编码,而不仅仅是接收时使用的格式。

浏览器支持 (Browser Support)

So far we’ve just covered the three “classic” image file formats — the original flavors that everyone knows and loves. Here’s where it starts to get tricky: browsers are all pushing different next-generation image formats. Chrome has the fantastic WebP, Edge supports JPEG XR and Safari has JPEG 2000.

到目前为止,我们仅介绍了三种“经典”图像文件格式-每个人都知道和喜欢的原始样式。 这就是开始变得棘手的地方:浏览器都在推动不同的下一代图像格式。 Chrome具有出色的WebP,Edge支持JPEG XR,而Safari具有JPEG 2000。

Browser Support for Next-Gen Image Formats

浏览器对下一代图像格式的支持

WebP JPEG XR JPEG 2000
Chrome Yes X X
Edge X Yes X
Safari X X Yes
Firefox X X X
WebP JPEG XR JPEG 2000
Chrome X X
边缘 X X
苹果浏览器 X X
火狐浏览器 X X X

WebP, for example, can give significantly better results than GIF, PNG, and JPEG in various scenarios. For the test image we’ve used above it comes in at 90.5Kb – a saving of around 15% from JPEG. However, you can currently only use this image type if the device requesting the image is Chrome, Opera, or the Android Browser.

例如,在各种情况下, WebP可以提供比GIF,PNG和JPEG更好的结果。 对于我们上面使用的测试图像,它的输入速度为90.5Kb ,比JPEG 节省了大约15% 。 但是,当前仅当请求图像的设备是Chrome,Opera或Android浏览器时才能使用此图像类型。

JPEG XR is Microsoft’s own format – JPEG eXtended Range – and improves on basic JPEG encoding, even supporting transparency (like PNG and WebP). The test image in JPEG XR format weighs 104Kb: around 2% shaved off the original JPEG image. Naturally, this is only for IE9+ and Edge, and as the name suggests it is most appropriate for photographic images.

JPEG XR是Microsoft自己的格式-JPEG扩展范围-并改进了基本JPEG编码,甚至支持透明性(如PNG和WebP)。 JPEG XR格式的测试图像重104Kb :与原始JPEG图像相比减少了大约2% 。 自然,这仅适用于IE9 +和Edge,顾名思义,它最适合摄影图像。

So not only do you have to ensure you’re using the most appropriate format for the image content, you also need to consider the most appropriate format for the device requesting the image. You might even need to create four or five versions of every image: one encoded in one of the classic three formats (for all devices), and one for each of the new, browser-specific, next-generation formats (to enjoy the optimization benefits of the new format). That’s a lot of time and effort.

因此,不仅必须确保对图像内容使用最合适的格式,而且还需要为请求图像的设备考虑最合适的格式。 您甚至可能需要为每个图像创建四个或五个版本:一个以经典的三种格式之一编码(适用于所有设备),另一种是针对特定于浏览器的新的下一代格式(以享受最佳化效果)新格式的好处)。 这是很多时间和精力。

即将推出的图像格式 (Upcoming Image Formats)

So far we’ve covered the “classic” formats that you can use in all browsers, and the impressive new formats available in some of the main browsers.

到目前为止,我们已经介绍了可在所有浏览器中使用的“经典”格式,以及一些主要浏览器中令人印象深刻的新格式。

Uneven browser support means that if we want to take advantage of the new formats, we need to create multiple, alternate versions of each image on our site.

对浏览器的不均匀支持意味着,如果我们想利用新格式,我们需要在我们的网站上为每个图像创建多个替代版本。

Now here’s a curve-ball: as-yet unsupported image formats. Formats like FLIF and BPG are in the wild, gaining traction, and it’s only a matter of time before one of the browsers rolls out support.

现在这是一个曲线球:尚不支持的图像格式。 诸如FLIF和BPG之类的格式大行其道,越来越受欢迎,而且其中一个浏览器推出支持只是时间问题。

What does this mean for you? You may have to regenerate all of your existing images in a new format or two, requiring even more time and effort.

这对您意味着什么? 您可能需要以一两种新格式重新生成所有现有图像,这需要更多的时间和精力。

Cloudinary的自动格式 (Cloudinary’s Auto Format)

Happily, there is one great solution out there: Cloudinary’s “auto format” feature lets you upload one original image — potentially even in the least appropriate format for the content — and by using one clever URL parameter you can deliver it in the most appropriate format for the end user, even if a new format comes out in the future.

令人高兴的是,这里有一个很棒的解决方案: Cloudinary的 “自动格式”功能可让您上传一张原始图片(甚至可能以最不适合内容的格式上传图片),并且通过使用一个巧妙的URL参数,您可以以最合适的格式上传图片对于最终用户,即使将来会推出新格式。

If we add the f_auto parameter into the image URL, the image format is now automatically determined by Cloudinary:

如果我们将f_auto参数添加到图像URL,则图像格式现在由Cloudinary自动确定:

http://res.cloudinary.com/otomotech/image/upload/w_800,f_auto/kite_xikqxa.jpg

http://res.cloudinary.com/otomotech/image/upload/w_800,f_auto/kite_xikqxa.jpg

Viewing that URL in Chrome will give a WebP response; in Edge it will be a JPEG XR image. In Firefox it will be the original-flavor JPEG.

在Chrome中查看该URL将给出WebP响应; 在Edge中,它将是JPEG XR图像。 在Firefox中,它将是原始样式的JPEG。

With this setting in your image references you will never have to worry about cross browser image format support — now or in the future. Extremely powerful, future-proofing stuff.

在图像参考中使用此设置,无论现在还是将来,您都不必担心跨浏览器图像格式的支持。 功能强大,面向未来的产品。

If you haven’t done so already, head over to Cloudinary for your free account.

如果您还没有这样做,请前往Cloudinary获取免费帐户 。

References

参考文献

  • Image format support

    图像格式支持

  • FLIF

    FLIF

  • BPG

    BPG

  • Upcoming support for future formats, example.

    即将支持将来的格式, 例如 。

This content is sponsored via Syndicate Ads.

该内容是通过辛迪加广告赞助的 。

翻译自: https://www.sitepoint.com/how-to-select-the-perfect-image-format-to-optimize-your-website/

微信小程序选择图片优化

微信小程序选择图片优化_如何选择完美的图像格式来优化您的网站相关推荐

  1. 微信小程序swiper图片尺寸_微信小程序 swiper 轮播图 高度自适应

    微信小程序 swiper 轮播图 高度自适应 发布时间:2018-07-20 15:34, 浏览次数:588 , 标签: swiper 小程序中使用swiper 组件 ,实现轮播图高度自适应效果. 先 ...

  2. 微信小程序swiper图片尺寸_微信小程序之swiper轮播图中的图片自适应高度的方法...

    小程序中的轮播图很简单,官方都有例子的,但是唯一的缺陷就是swiper是固定死的150px高度,这样如果传入的图片大于这个高度就会被隐藏.辣么,怎样让图片自适应不同分辨率捏. 我的思路是:获取屏幕宽度 ...

  3. 微信小程序swiper图片尺寸_微信小程序之swiper轮播图中的图片自适应高度

    小程序中的轮播图很简单,官方都有例子的,但是唯一的缺陷就是swiper是固定死的150px高度,这样如果传入的图片大于这个高度就会被隐藏.辣么,怎样让图片自适应不同分辨率捏. 我的思路是:获取屏幕宽度 ...

  4. 微信小程序swiper图片尺寸_微信小程序 - swiper 高度自适应

    我这边开发用的是 wepy,代码风格跟小程序原生的不太一样,下面代码是依照小程序的代码风格整理之后的,可能有不同或遗漏的地方,但这都不重要,注意领会精神! 原理: 获取设备宽度 获取 swiper 内 ...

  5. 微信小程序swiper图片尺寸_微信小程序swiper组件中的img自定义尺寸(自适应)

    swiper组件里的image默认宽度320,高度200,这无法满足我们的需求,就需要我们自己修改尺寸和属性了,这里记录下自己的解决办法.首先给image的width设置为100%,此时图片的大小会根 ...

  6. 微信小程相对图片路径_微信小程序----相对路径图片不显示

    出现场景 在本地调试的时候本地图片显示,但是手机浏览的时候本地图片不显示. 出现图片不显示的原因 小程序只支持网络路径和base64的图片.图片转base64在线工具 处理方法 将图片都放到服务器,然 ...

  7. 微信小程序预览服务器图片,微信小程序实现图片选择并预览功能

    本文实例为大家分享了微信小程序实现图片选择并预览的具体代码,供大家参考,具体内容如下 (一).功能说明 做的是一个意见反馈,用户发表意见和上传图片,限制了最多只能上传三张图片. 其他要点:textar ...

  8. ready等方法 微信小程序_微信小程序设置图片固定比例

    小编了解到,微信小程序成为当下热门话题,下面从多个方面来谈谈微信小程序设置图片固定比例 . 12月28日消息,微信官方日前发布消息称,为了让微信小程序相关成员在无线端更方便地管理微信小程序,将开发小程 ...

  9. 微信小程序实现图片是上传、预览功能

    本文实例讲述了微信小程序实现图片上传.删除和预览功能的方法,分享给大家供大家参考,具体如下: 这里主要介绍一下微信小程序的图片上传图片删除和图片预览 1.可以调用相机也可以从本地相册选择 2.本地实现 ...

  10. Java实现微信小程序校验图片是否含有违法违规内容

    文章目录 1.Java实现微信小程序校验图片是否含有违法违规内容(security.imgSecCheck) 2.接口文档简述 3.Java实现对接接口 4.压缩图片(Thumbnails) 5.整合 ...

最新文章

  1. 支持量子机器学习,王海峰发布最新百度飞桨全景图
  2. 人脸对齐--Dense Face Alignment
  3. 《移动优先与响应式Web设计》一1.2 设备不同,功能不同
  4. html页面之间传参乱码,急求教,在两个htm页面传参数时中文出现了乱码,试了网上的方法不管用。_html/css_WEB-ITnose...
  5. 蚂蚁集团沈凋墨:Kubernetes-微内核的分布式操作系统
  6. python基本语法 关于雷达模拟实践
  7. Java和C语言学习那个比较好?
  8. 常用STL整理 (施工中 2017.8.11更新)
  9. Intouch2020安装与授权
  10. Photoshop插件-HDR(二)-脚本开发-PS插件
  11. [软件更新]LeadBBS 6.0正式发布(更新日志和下载)
  12. 结构力学用计算机算的优势和不足,计算结构力学
  13. python数据分析挖掘与可视化课件_python数据分析与可视化
  14. 关于Arcgis中的裁剪说明
  15. java如何获取hostid_将Unix hostid转换为Java
  16. zk集群和clickhouse集群搭建
  17. 赛福基因公开课第二节《神经系统遗传病基因检测简介》
  18. C#中Validating和Validated事件
  19. python下载微信公众号文章_一步步教你打造微信公众号文章爬虫(3)-批量下载
  20. OpenCV中图像的深度

热门文章

  1. 适合购买免备案云服务器一般是哪些网站业务?
  2. FPGA芯片选型(FPGA初学者的选择)
  3. Android push到/system/app下,导致找不到so文件,抛出java.lang.UnsatisfiedLinkError的原因分析和解决方案
  4. FusionInsight HD 华为大数据平台
  5. 如何实现一个去中心化的 Dropbox 存储
  6. linux gcc配置安装文件失败,安装一些环境时提示安装不成功帮一下看看什么情况(apt-get install gcc g++ ssh...
  7. 想学明白PostgreSQL,得先捋一捋体系架构
  8. 游戏服务端(MMORPG)的基础算法一、AOI
  9. ICLR 2020|PairNorm: Tackling Oversmoothing in GNNs
  10. tf.matrix_diag和tf.matrix_inverse的用法(tensorflow如何生成对角矩阵和求逆矩阵)