<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Sharp on Bigshans&#39; Blog</title>
    <link>https://bigshans.github.io/tags/sharp/</link>
    <description>Recent content in Sharp on Bigshans&#39; Blog</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>bigshans</copyright>
    <lastBuildDate>Tue, 24 Aug 2021 18:20:53 +0800</lastBuildDate>
    <atom:link href="https://bigshans.github.io/tags/sharp/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>使用 Sharp 压缩图片、改变图片大小</title>
      <link>https://bigshans.github.io/post/sharp/</link>
      <pubDate>Tue, 24 Aug 2021 18:20:53 +0800</pubDate>
      <guid>https://bigshans.github.io/post/sharp/</guid>
      <description>&lt;p&gt;因为业务需要就写了个图片压缩服务，顺带改变大小，因为用的是 nodejs ，于是我就选择了 &lt;a href=&#34;https://github.com/lovell/sharp&#34;&gt;sharp&lt;/a&gt; ，基于 libvips。&lt;/p&gt;&#xA;&lt;p&gt;代码非常好写：&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code class=&#34;language-javascript&#34;&gt;function resize(input, x, y) {&#xA;    return sharp(input)&#xA;        .resize(x, y, { fit: &#39;inside&#39; })&#xA;        .toBuffer();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;默认是裁剪模式，但我们要保持比例，因此用 “inside” 。因为我们还要调整一下质量，因为原始文件太大了。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
