vivo 手机 拍照 特殊jpg格式 批量压缩

https://github.com/tjko/jpegoptim

Windows (setargv.obj "link option" is needed for wildcards expansion to work)

 

 

 

 

 

 

https://github.com/mozilla/mozjpeg 是个库   MozJPEG is a patch for libjpeg-turbo.

https://github.com/ImageProcessing-ElectronicPublications/jpeg-recompress   star比较少

https://sharp.pixelplumbing.com/api-input/ Node.js库 使用libvips

https://github.com/Lymphatus/caesium-image-compressor      gui软件

https://medium.com/@jack.yin/comparison-of-jpeg-lossless-compression-tools-963e02f79996

https://github.com/fengyuanchen/compressorjs    Uses the Browser's native HTMLCanvasElement.toBlob() method to do the compression work

FFmpeg 用 -q:v 是比较粗糙的控制方式,不像专门的 JPEG 优化工具 (如 MozJPEG、Guetzli) 那样灵活或高效。

https://tinyjpg.com/developers/reference/python 需要联网请求

 

https://cyber.meme.tips/jpdump/ 在线网页 只能查看第一个图片的

 

https://www.libvips.org/API/8.17/using-the-cli.html

https://www.libvips.org/API/8.17/method.Image.jpegsave.html

vips copy photo.jpg photo_compressed.jpg[Q=70,strip,optimize_coding]

vips copy input.jpg output.jpg[Q=85,strip,optimize_coding]

 

 

图像处理相关库

sharp 依赖 libvips 依赖 libjpeg/libjpeg-turbo  libheif

 

 

 

 

手册

JPEGOPTIM(1)                General Commands Manual               JPEGOPTIM(1)

 

NAME
       jpegoptim - utility to optimize/compress JPEG/JFIF files.

 

SYNOPSIS
       jpegoptim [ options ] [ filenames ]


DESCRIPTION
       jpegoptim  is  used  to  optimize/compress jpeg files.  Program supports lossless optimization,  which is based on optimizing the Huffman tables.  And  so  called  "lossy"  optimization  where in addition to optimizing Huffman tables user can specify upperlimit for image quality. 

       NOTE! By default jpegoptim modifies the input files (if they are  opti-         mized),   to  preserve original files use option -d to specify alternate         directory for saving the optimized files to. 

       Only normal files are optimized (symbolic links and special  files  are         skipped).    Also,   any other hard links to the file being optimized (as         created using link(2)) are unaffected. 

 

OPTIONS
       Options may be either the traditional POSIX one letter options,  or  the         GNU style long options.   POSIX style options start with a single ``-'',          while GNU long options start with ``--''. 

       Options offered by jpegoptim are the following:

       -d<path>, --dest=<path>
             Sets alternative destination directory where  to  save  optimized               files  (default  is to overwrite the originals).  Please note that               unchanged files won't be added to the destination directory.  This               means  if  the  source  file can't be compressed,  no file will be               created in the destination path. 

       -f, --force
             Force optimization, even if the result would be larger  than  the
             original file.

       -h, --help
             Displays short usage information and exits.

       -m<quality>, --max=<quality>
             Sets  the  maximum  image quality factor (disables lossless opti-               mization mode,  which is by default enabled).  This option will re-               duce  quality  of those source files that were saved using higher               quality setting.   While files that  already  have  lower  quality               setting  will  be  compressed  using  the  lossless  optimization               method. 

             Valid values for quality parameter are: 0 - 100

       -n, --noaction
             Don't really optimize files, just print results.

       -S<size>, --size=<size>
             Try to optimize file to given size (disables  lossless  optimiza-               tion  mode).  Target size is specified either in kilobytes (1 n)               or as percentage (1% 99%) of the original file size. 

       -T<threshold>, --threshold=<threshold>
             Keep the file unchanged if the compression gain is lower than the
             threshold (%).

             Valid values for threshold are: 0 - 100

       -w<max>, --workers=<max>
             Set  the maximum number of parallel processes to launch.  (Default               is 1)


       -b, --csv
             Print progress info in CSV format.

       -o, --overwrite
             Overwrite target file even if it exists (when using -d option).

       -p, --preserve
             Preserve file modification times.

       -P, --preserve-perms
             Preserve file permissions (owner/group) by overwriting the origi-               nal file.  This is slightly less safe than the default mode of op-               eration (where new file is first saved as temporary file and then               renamed  over  the  original file).   In this mode a backup of the               original file is made with  . jpegoptim. bak  extension,   and  this               file is removed after the original file has been successfully re-               placed.   NOTE! if running jpegoptim as root there is generally no               need  to  use  this option,  as jpegoptim is able to preserve file               permissions when run by root in default mode. 

       -q, --quiet
             Quiet mode.

       -r, --retry
             Recursively re-try compression until output file  size  does  not
             get  smaller anymore.  This can result a few bytes smaller output
             file, but with the expense of lot more computing time used.

             NOTE! This option is on only effective when used in  compbination
             with -m (--max) or -S (--size) option.

       -t, --totals
             Print totals after processing all files.

       -v, --verbose
             Enables verbose mode (positively chatty).


       --auto-mode
             Select  progressive  vs  non-progressive  mode based on which one               produces smaller output file.  By  default  mode  (progressive  vs               non-progressive) is preserved. 

       --all-normal
             Force all output files to be non-progressive.  Can be used to con-               vert all input files to  non-progressive  JPEGs  when  used  with               --force option. 

       --all-progressive
             Force  all output files to be progressive.  Can be used to convert               all normal (non-progressive) JPEGs  input  files  to  progressive               when used with --force option. Progressive JPEG(渐进式 JPEG):图像在编码时分成多个“扫描(pass)”层。加载时先显示一个整体模糊轮廓,然后随着更多数据到来,图像逐渐变清晰。


       --all-arith
             Force  all output files to use Arithmetic Coding.   This option is               experimental and only available if jpegoptim  was  compiled  with               Arithmetic Coding support enabled. 

       --all-huffman
             Force all output files to use (traditional) Huffman coding.   This               option is experimental and only available if jpegoptim  was  com-               piled with Arithmetic Coding support enabled. 


       --nofix
             Skip  processing of any input files that have any errors/warnings               during decompression.   By default jpegoptim will attempt to opti-               mize  any  file that it is able to decompress,  even if decompres-               sion generates warnings.  This will 'fix' some (corrupt) JPEG  images  automatically.    If this behaviour is not desired,  this op-               tion can be used to make jpegoptim to skip any input  files  that               contain any errors. 


       --save-extra
             Save  extraneous  data  after  end of the JPEG image in the input               file (default is to discard any extraneous data after the end  of               image  that  may  be  present).   This may be useful if JPEG image               contains non-standard extensions that are not part  of  the  JPEG               image  format.   NOTE! This option does not work if input JPEG im-               age is read from standard input (stdin). 

 

       --stdout
             Send output image  to  standard  output.   Note,   if  optimization               didn't  create  smaller  file than the input file,  then no output               original image is passed through  unmodified  (except  any  extra               data after JPEG image will be discarded). 


       --stdin
             Read  input image from standard input and send output to standard               output (--stdout is assumed when this option is used).   When this               option  is  used then only one image is read from standard input.                Any (other) input files specified on  command-line  are  ignored.                Note,  if input file '-' is seen on command line then standard in-               put is also assumed. 


       --files-stdin
             Read names of files to process from standard input. One  filename
             per line.


       --files-from=<filename>
             Read  names  of  files  to  process from a file. One filename per
             line.

 

METADATA OPTIONS
       By default jpegoptim will keep common metadata (JPEG markers) and  dis-         card any other (unknown ones). 

       Following markers are kept by default:
        - EXIF
        - IPTC
        - ICC
        - XMP
        - COM (JPEG Comment markers)

       JFIF  marker  will be regenerated (by libjpeg) during the process (this         cannot be changed).   However,  Adobe marker is also generated (or  omit-         ted)  by libjpeg based on the image colorspace,  etc.   This behavior de-         pends on libjpeg library version being used.  To make sure Adobe  marker         is preserved option --keep-adobe can be used. 

       To  remove  additional markers one or more the --strip-* options can be
       used.

       For example:      --strip-icc --strip-xmp --strip-com


       Alternatively it is possible to specify --strip-all  and  then  one  or
       more of the --keep-* options to explicitly list which markers to keep

       For example:      --strip-all --keep-exif --keep-iptc


       Options for controlling metadata (markers) in output files:


       -s, --strip-all
             Strip  all  markers from output file. (NOTE! by default only Com-
             ment & Exif/IPTC/PhotoShop/ICC/XMP markers are  kept,  everything
             else  is  discarded).  Output JPEG still likely will contains one
             or two markers (JFIF and Adobe  APP14)  depending  on  colorspace
             used  in the image, as these markers are generated by the libjpeg
             encoder automatically.

       --strip-none, --keep-all
             Preserve "all" markers in the image. This will leave all  markers
             untouched  in  the  image,  except  JFIF (APP0) and Adobe (APP14)
             markers as those get regenerated by the libjpeg library.

             NOTE! If this option is specified then  any  other  --strip-*  or
             --keep-* options are ignored.


       --strip-com
             Strip Comment (COM) markers from output file.

       --strip-exif
             Strip EXIF markers from output file.

       --strip-iptc
             Strip IPTC / Adobe Photoshop (APP13) markers from output file.

       --strip-icc
             Strip ICC profiles from output file.

       --strip-xmp
             Strip XMP profiles from output file.

       --strip-jfif
             Strip JFIF markers from output file.

       --strip-jfxx
             Strip JFXX (JFIF Extensions) markers from output file.

       --strip-adobe
             Strip Adobe markers from output file.

 

       --keep-com
             Do not strip any Comment (COM) markers from output file.

       --keep-exif
             Do not strip any EXIF markers from output file.

       --keep-iptc
             Do not strip any IPTC / Adobe Photoshop (APP13) markers from out-
             put file.

       --keep-icc
             Do not strip any ICC profiles from output file.

       --keep-xmp
             Do not strip any XMP profiles from output file.

       --keep-jfif
             Do not strip any JFIF markers from output file.

       --keep-jfxx
             Do not strip any JFXX (JFIF Extensions) markers from output file.

       --keep-adobe
             Do not strip Adobe markers from output file.

 


BUGS
       When using --size option,  resulting file is not always exactly the  re-         quested  size.  Workaround is to re-run jpegoptim on the same file again         which often will result file closer to target size. 


SEE ALSO
       jpeginfo(1)


AUTHOR
       Timo Kokkonen <tjko@iki.fi>


COPYING
       Copyright (C) 1996-2025  Timo Kokkonen

       This program is free software; you can redistribute it and/or modify it
       under  the  terms of the GNU General Public License as published by the
       Free Software Foundation; either version 2 of the License, or (at  your
       option) any later version.

       This  program  is  distributed  in the hope that it will be useful, but
       WITHOUT ANY  WARRANTY;  without  even  the  implied  warranty  of  MER-
       CHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
       Public License for more details.

       You should have received a copy of the GNU General Public License along
       with this program; if not, write to the Free Software Foundation, Inc.,
       51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

 

4th Berkeley Distribution         28 Jan 2025                     JPEGOPTIM(1)

 

 

 

 

APP 段    标记 (hex)    常见用途
APP0    FFE0    JFIF/缩略图
APP1    FFE1    EXIF, XMP
APP2    FFE2    ICC Profile, FlashPix
APP3    FFE3    厂商自定义 (少见)
APP4    FFE4    厂商自定义
APP5    FFE5    厂商自定义/打印相关
APP6    FFE6    少见,某些标准
APP7    FFE7    厂商自定义
APP8    FFE8    SPIFF 标准 (已过时)
APP9    FFE9    厂商自定义 (MPD 等)
APP10    FFEA    Kodak/HP 相册信息
APP11    FFEB    HDR-JPEG, IPTC/NAA

 

.\jpegoptim.exe .\IMG_20250924_000219_optimtest.jpg

Name                               Length LastWriteTime
----                               ------ -------------
00000000.jpeg                     2167406 2025/11/18 20:52:49    optimtest提取出来的2张
00000724.jpeg                        7854 2025/11/18 20:52:49

IMG_20250924_000219.jpg           3599113 2025/9/23 18:02:22
IMG_20250924_000219_optimtest.jpg 2167406 2025/11/18 16:49:22

 

 

处理前后,大小3.43MB 到2.06MB,打开放大看了一下,像素内容没变化。

 

 

 

Get-ChildItem . | Select-Object Name, Length, LastWriteTime

Name                               Length LastWriteTime
----                               ------ -------------
00000000.jpeg                     2801563 2025/11/18 20:58:57    原图提取出来的5张
00000724.jpeg                        7854 2025/11/18 20:58:57
002abfb3.jpeg                       50274 2025/11/18 20:58:57
002c3b6a.jpeg                      699733 2025/11/18 20:58:57
002c40ea.jpeg                        1213 2025/11/18 20:58:57

 

2801563+7854+50274+699733+1213=3560637


IMG_20250924_000219.jpg           3599113 2025/9/23 18:02:22
IMG_20250924_000219_optimtest.jpg 2167406 2025/11/18 16:49:22

 

 

python jpegdump.py -f -c -e IMG_20250924_000219.jpg

cursor终端里运行会有一段奇怪的重复,不知道为什么,powershell里运行是正常的。

image

 

 

--save-extra

.\jpegoptim.exe --save-extra .\IMG_20251001_172433saveextra.jpg
.\IMG_20251001_172433saveextra.jpg 3060x4080 24bit N Exif,ICC (1307189 bytes extraneous data found after end of image)  [OK] 7555951 --> 6638113 bytes (12.15%), optimized.

.\jpegoptim.exe .\IMG_20251001_172433_optimtest.jpg
.\IMG_20251001_172433_optimtest.jpg 3060x4080 24bit N Exif,ICC (1307189 bytes extraneous data found after end of image)  [OK] 7555951 --> 5330924 bytes (29.45%), optimized.

python jpegdump.py -f -c -e .\IMG_20251001_172433saveextra.jpg
File: .\IMG_20251001_172433saveextra.jpg
Found SOI:
  1 p=0x00000000    : m=ffd8 SOI
  2 p=0x00000002 d=0: m=ffe1 APP1  l=51596 e=2.114622 a=14.244743
  3 p=0x0000c990 d=0: m=ffe2 APP2  l=  564 e=4.070801 a=35.837790
  4 p=0x0000cbc6 d=0: m=ffdb DQT   l=  132 e=2.761176 a=0.589147 remark: 130/65 = 2.000000
  5 p=0x0000cc4c d=0: m=ffc0 SOF0  l=   17 e=3.323231 a=76.357143 remark: p=8 h=4080 w=3060 c=3
  6 p=0x0000cc5f d=0: m=ffc4 DHT   l=  239 e=5.841939 a=32.169492
  7 p=0x0000cd50 d=0: m=ffda SOS   l=   12 e=2.446439 a=21.222222 remark: c=3
                                  entropy-coded data: l=5278348 e=7.967776 a=84.099467 #ff00=19098
  8 p=0x005157ea d=0: m=ffd9 EOI
Found SOI:
  1 p=0x00000710    : m=ffd8 SOI
  2 p=0x00000712 d=0: m=ffe0 APP0  l=   16 e=1.985228 a=6.615385
  3 p=0x00000724 d=0: m=ffdb DQT   l=   67 e=4.506929 a=2.781250 remark: 65/65 = 1.000000
  4 p=0x00000769 d=0: m=ffdb DQT   l=   67 e=1.375467 a=1.078125 remark: 65/65 = 1.000000
  5 p=0x000007ae d=0: m=ffc0 SOF0  l=   17 e=3.006239 a=57.928571 remark: p=8 h=192 w=144 c=3
  6 p=0x000007c1 d=0: m=ffc4 DHT   l=   31 e=2.815937 a=0.750000
  7 p=0x000007e2 d=0: m=ffc4 DHT   l=  181 e=7.270047 a=13.168539
  8 p=0x00000899 d=0: m=ffc4 DHT   l=   31 e=2.799180 a=0.642857
  9 p=0x000008ba d=0: m=ffc4 DHT   l=  181 e=7.243483 a=18.140449
 10 p=0x00000971 d=0: m=ffda SOS   l=   12 e=2.446439 a=21.222222 remark: c=3
                                  entropy-coded data: l=7825 e=7.951519 a=87.032081 #ff00=28
 11 p=0x00002810 d=0: m=ffd9 EOI
Found SOI:
  1 p=0x005157f6    : m=ffd8 SOI
  2 p=0x005157f8 d=0: m=ffe1 APP1  l=51196 e=1.053391 a=6.302561
  3 p=0x00521ff6 d=0: m=ffe2 APP2  l=  564 e=4.070801 a=35.837790
  4 p=0x0052222c d=0: m=ffe5 APP5  l=65406 e=0.012234 a=0.067107
  5 p=0x005321ac d=0: m=ffe6 APP6  l=65406 e=0.000000 a=0.000000
  6 p=0x0054212c d=0: m=ffe7 APP7  l=65406 e=0.000000 a=0.000000
  7 p=0x005520ac d=0: m=ffe8 APP8  l=65406 e=0.000000 a=0.000000
  8 p=0x0056202c d=0: m=ffe9 APP9  l=65406 e=3.679414 a=46.448435
  9 p=0x00571fac d=0: m=ffe9 APP9  l=65406 e=4.392761 a=87.458465
 10 p=0x00581f2c d=0: m=ffea APP10 l=65406 e=1.685760 a=15.264774
 11 p=0x00591eac d=0: m=ffea APP10 l=65406 e=0.000000 a=0.000000
 12 p=0x005a1e2c d=0: m=ffeb APP11 l=65406 e=0.485698 a=1.973610
 13 p=0x005b1dac d=0: m=ffdb DQT   l=   67 e=3.255574 a=0.828125 remark: 65/65 = 1.000000
 14 p=0x005b1df1 d=0: m=ffdb DQT   l=   67 e=1.350020 a=0.265625 remark: 65/65 = 1.000000
 15 p=0x005b1e36 d=0: m=ffc0 SOF0  l=   17 e=3.323231 a=79.357143 remark: p=8 h=2040 w=1530 c=3
 16 p=0x005b1e49 d=0: m=ffc4 DHT   l=   31 e=2.815937 a=0.750000
 17 p=0x005b1e6a d=0: m=ffc4 DHT   l=  181 e=7.270047 a=13.168539
 18 p=0x005b1f21 d=0: m=ffc4 DHT   l=   31 e=2.799180 a=0.642857
 19 p=0x005b1f42 d=0: m=ffc4 DHT   l=  181 e=7.243483 a=18.140449
 20 p=0x005b1ff9 d=0: m=ffda SOS   l=   12 e=2.446439 a=21.222222 remark: c=3
                                  entropy-coded data: l=665645 e=7.969928 a=86.331133 #ff00=2609
 21 p=0x00654834 d=0: m=ffd9 EOI
Found SOI:
  1 p=0x00515d76    : m=ffd8 SOI
  2 p=0x00515d78 d=0: m=ffe0 APP0  l=   16 e=1.985228 a=6.615385
  3 p=0x00515d8a d=0: m=ffdb DQT   l=   67 e=4.506929 a=2.781250 remark: 65/65 = 1.000000
  4 p=0x00515dcf d=0: m=ffdb DQT   l=   67 e=1.375467 a=1.078125 remark: 65/65 = 1.000000
  5 p=0x00515e14 d=0: m=ffc0 SOF0  l=   17 e=3.006239 a=57.928571 remark: p=8 h=192 w=144 c=3
  6 p=0x00515e27 d=0: m=ffc4 DHT   l=   31 e=2.815937 a=0.750000
  7 p=0x00515e48 d=0: m=ffc4 DHT   l=  181 e=7.270047 a=13.168539
  8 p=0x00515eff d=0: m=ffc4 DHT   l=   31 e=2.799180 a=0.642857
  9 p=0x00515f20 d=0: m=ffc4 DHT   l=  181 e=7.243483 a=18.140449
 10 p=0x00515fd7 d=0: m=ffda SOS   l=   12 e=2.446439 a=21.222222 remark: c=3
                                  entropy-coded data: l=3122 e=7.874493 a=87.962832 #ff00=8
 11 p=0x00516c17 d=0: m=ffd9 EOI

 

image

posted @ 2025-11-19 04:35  hrdom  阅读(3)  评论(0)    收藏  举报