dongmeng2687 2019-07-14 16:31 采纳率: 0%
浏览 296

如何使用php中的imagejpeg在Kb中设置特定压缩

I'm trying to compress uploaded images down to a specific size of 200Kb. I don't want to compress them any more than they need to be and using lossless compression like PNG isn't enough. Simply setting it to imagejpeg($image, null, 40) creates different compressed sizes for different images. Is there a way to set the desired compression size in bytes or at least have some algorithm that can find out the compression output without looping through imagejpeg() from 100 to 0 quality?

  • 写回答

2条回答 默认 最新

  • dpp3047 2019-07-15 03:49
    关注

    There really isn't any way to predict the level of compression beforehand. The effect of compression depends upon the image source. One of the problems is that there is a myriad of JPEG compression settings.

    1. The quantization tables (up to 3) with 64 different values.
    2. Sub sampling.
    3. Spectral selection in progressive scans.
    4. Successive Approximation in progressive scans.
    5. Optimize huffman tables.

    So there are billions upon billions of parameters that you can set.

    There are JPEG optimization applications out there that will look at the compressed data.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器