Giter Club home page Giter Club logo

compressionimage's Introduction

CompressionImage

图片的“压”和“缩”概念

  • “压” 是指文件体积变小,但是像素数不变,长宽尺寸不变,那么质量可能下降。
  • “缩” 是指文件的尺寸变小,也就是像素数减少,而长宽尺寸变小,文件体积同样会减小。

图片压缩策略: 拿到图片后 根据设定大小进行 缩大小(策略来源于网络):

  • 宽高均<= 1334,图片尺寸大小保持不变
  • 宽或高> 1334 && 宽高比<= 2,取较大值等于1334,较小值等比例压缩
  • 宽或高> 1334 && 宽高比> 2 && 宽或高< 1334,图片尺寸大小保持不变
  • 宽高均> 1334 && 宽高比> 2,取较小值等于1334,较大值等比例压缩

拿到对应的图片size,为降低CPU消耗使用Image I/O进行新图片生成 用新图片 使用二分法 进行压质量。

博客:https://yimouleng.com/2019/01/24/%E5%9B%BE%E7%89%87%E5%8E%8B%E7%BC%A9/

使用

#import "UIImage+Compression.h"
UIImage * thumbImage = [self.image compressToImage];

压缩对比

原图 压缩后
4016 * 3012, 15.19MB 1334 * 1001, 224KB
1125 * 2436, 2.6MB 1125 * 2436, 158KB
2880 * 1800, 5.91MB 1334 * 834, 154KB
1080 * 1920, 1.29MB 750 * 1334, 238KB
720 * 1280, 730KB 750 * 1334, 96KB
1280 * 1280, 2.06MB 1280 * 1280, 219KB

具体可下载demo后自行试验

compressionimage's People

Contributors

yimouleng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.