Skip to content

存在严重 bug,这么多用的人都没发现嘛 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
poos opened this issue Nov 21, 2018 · 1 comment
Open

存在严重 bug,这么多用的人都没发现嘛 #2

poos opened this issue Nov 21, 2018 · 1 comment

Comments

@poos
Copy link

poos commented Nov 21, 2018

Mozi/Mozi/Classes/Mozi.swift

发现2个严重 bug:

  1. 121行,resize image 方法:

当处于第一区间时候,尺寸不仅没有缩小反而变大了,而鲁班算法会要求 n >= 1 等才会 * factor

let toSize = CGSize(width: self.size.width * factor, height: self.size.height * factor)

事实上已经计算了图片尺寸,不需要再乘以比例系数了

let toSize: CGSize if self.size.height > self.size.width { toSize = CGSize.init(width: size.width, height: size.height) } else { toSize = CGSize.init(width: size.height, height: size.width) }

  1. 141行 压缩大小的方法:

老哥鲁班计算的是 kb, 而你没有* 1024,比较的是字节,99.9%的图片都跑到这里循环10遍,然后返回了 压缩系数 0.1 的值

while CGFloat(data.count) > size && compression > maxCompression {

乘以1024即可换算为 kb

while CGFloat(data.count) > size * 1024 && compression > maxCompression {

60多赞的都没发现嘛。老哥,代码没测好啊。。。

@poos
Copy link
Author

poos commented Jan 16, 2019

还发现56行类型对应错误

if ratio > 0 && ratio <= 0.5 { // [1:2 ~ 1:∞) self = .rectangle(minValue: minV, maxValue: maxV)
之前对应的是 .square(minValue: minV, maxValue: maxV)

Repository owner deleted a comment from HMR25 Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant