0

I have tried using jpegoptim and even tried the manpage but am stumped. Here is a file I want to reduce to 50k and even open to reducing quality of the data -

Image:
  Filename: shirish.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 4624x3468+0+0
  Resolution: 72x72
  Print size: 64.2222x48.1667
  Units: PixelsPerInch
  Colorspace: sRGB
  Type: TrueColor
  Base type: Undefined
  Endianness: Undefined
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Pixels: 16036032
    Red:
      min: 0  (0)
      max: 255 (1)
      mean: 119.779 (0.46972)
      standard deviation: 60.359 (0.236702)
      kurtosis: -1.33094
      skewness: -0.2895
      entropy: 0.920909
    Green:
      min: 0  (0)
      max: 255 (1)
      mean: 115.071 (0.45126)
      standard deviation: 63.5402 (0.249177)
      kurtosis: -1.51367
      skewness: -0.162973
      entropy: 0.912909
    Blue:
      min: 0  (0)
      max: 255 (1)
      mean: 114.566 (0.449277)
      standard deviation: 61.8685 (0.242621)
      kurtosis: -1.51015
      skewness: -0.101152
      entropy: 0.912805
  Image statistics:
    Overall:
      min: 0  (0)
      max: 255 (1)
      mean: 116.472 (0.456752)
      standard deviation: 61.9226 (0.242834)
      kurtosis: -1.46062
      skewness: -0.184944
      entropy: 0.915541
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 4624x3468+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 92
  Orientation: RightTop
  Profiles:
    Profile-app4: 7600 bytes
    Profile-exif: 51509 bytes
  Properties:
    date:create: 2022-08-20T05:27:53+00:00
    date:modify: 2022-08-20T05:27:53+00:00
    exif:ApertureValue: 169/100
    exif:BrightnessValue: 264/100
    exif:ColorSpace: 1
    exif:DateTime: 2022:08:20 10:53:10
    exif:DateTimeDigitized: 2022:08:20 10:53:10
    exif:DateTimeOriginal: 2022:08:20 10:53:10
    exif:DigitalZoomRatio: 100/100
    exif:ExifOffset: 226
    exif:ExifVersion: 48, 50, 50, 48
    exif:ExposureMode: 0
    exif:ExposureProgram: 2
    exif:ExposureTime: 1/50
    exif:Flash: 0
    exif:FNumber: 180/100
    exif:FocalLength: 532/100
    exif:FocalLengthIn35mmFilm: 28
    exif:ImageLength: 3468
    exif:ImageUniqueID: I64ELODR0PM
    exif:ImageWidth: 4624
    exif:Make: samsung
    exif:MaxApertureValue: 169/100
    exif:MeteringMode: 2
    exif:Model: SM-M526B
    exif:OffsetTime: +05:30
    exif:OffsetTimeOriginal: +05:30
    exif:PhotographicSensitivity: 160
    exif:PixelXDimension: 4624
    exif:PixelYDimension: 3468
    exif:SceneCaptureType: 0
    exif:ShutterSpeedValue: 1/50
    exif:Software: M526BXXU1BVG4
    exif:thumbnail:Compression: 6
    exif:thumbnail:ImageLength: 384
    exif:thumbnail:ImageWidth: 512
    exif:thumbnail:JPEGInterchangeFormat: 782
    exif:thumbnail:JPEGInterchangeFormatLength: 50721
    exif:thumbnail:ResolutionUnit: 2
    exif:thumbnail:XResolution: 72/1
    exif:thumbnail:YResolution: 72/1
    exif:WhiteBalance: 0
    exif:YCbCrPositioning: 1
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x2,1x1,1x1
    signature: 7841c1e0cbe1aa5b79f0dea6791ffd321e2cf05715a9ab3cd210fd551c9bf355
  Artifacts:
    filename: shirish.jpg
    verbose: true
  Tainted: False
  Filesize: 3.65599MiB
  Number pixels: 16.036M
  Pixels per second: 126.41MB
  User time: 0.120u
  Elapsed time: 0:01.126
  Version: ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org

Now I tried both imagemagick convert as well as jpegoptim to get a file which is around 50k. I need the file at that size as I have to upload it somewhere and there are size contraints.

I got the above exif and photo data using the identify -verbose switch in imagemagick.

Could somebody help me in the above.

I did try the following -

$jpegoptim --size=50k shirish.jpg

Instead of 50kb I got a file that is 200 kb, good but not what I wanted :(

I even tried -

$jpegoptim --max=10 --size=50k shirish-aadhar-2-reduced.jpg

But even that did not produce the desired results.

$ jpegoptim --version
jpegoptim v1.4.7  x86_64-pc-linux-gnu (Jun 20 2022)
Copyright (C) 1996-2022, Timo Kokkonen

This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistirbute it under certain conditions.
See the GNU General Public License for more details.


libjpeg version: 6b  27-Mar-1998
Copyright (C) 1991-2021 The libjpeg-turbo Project and many others

Looking forward for help. I know I could use some online tool for the same, but would like offline it possible.

1
  • I don't want to because it is sensitive, but can share other images, basically, any photo from mobile would have similar resolutions and whatnot. You can read the discussion which I moved to chat. thank you.
    – shirish
    Aug 20, 2022 at 14:52

2 Answers 2

1

You can use ImageMagick to strip all metadata and decrease the quality. Check this answer for more info:

quality in 85
progressive (comprobed compression)
a very tiny gausssian blur to optimize the size (0.05 or 0.5 of radius) depends on the quality and size of the picture, this notably
optimizes the size of the jpeg.
Strip any comment or EXIF metadata

in imagemagick should be

convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% source.jpg result.jpg

or in the newer version:

magick source.jpg -strip -interlace Plane -gaussian-blur 0.05 -quality 85% result.jpg

You can play with -quality number. But compress 16MP image to 50k will produce not so pleasant results.

9
  • magick doesn't seem to be a command? $ magick --version Command 'magick' not found, did you mean: command 'magics' from deb magics++ command 'magic' from deb magic Try: sudo apt install <deb name>
    – shirish
    Aug 20, 2022 at 6:37
  • @shirish, install ImageMagick: apt install imagemagick Aug 20, 2022 at 6:39
  • I already have it - ~$ apt-cache policy imagemagick imagemagick: Installed: 8:6.9.11.60+dfsg-1.3+b2 Candidate: 8:6.9.11.60+dfsg-1.3+b2 Version table: 8:6.9.12.20+dfsg1-1.2 100 100 deb.debian.org/debian experimental/main amd64 Packages *** 8:6.9.11.60+dfsg-1.3+b2 900 900 deb.debian.org/debian testing/main amd64 Packages 100 deb.debian.org/debian unstable/main amd64 Packages 100 /var/lib/dpkg/status
    – shirish
    Aug 20, 2022 at 6:40
  • seems it is part of 'source releases' and not binary releases. imagemagick.org/Magick++
    – shirish
    Aug 20, 2022 at 6:41
  • $ dpkg -L imagemagick | grep magick /usr/share/doc/imagemagick /usr/share/doc/imagemagick/NEWS.Debian.gz /usr/share/doc/imagemagick/changelog.Debian.amd64.gz /usr/share/doc/imagemagick/changelog.Debian.gz /usr/share/doc/imagemagick/changelog.gz /usr/share/doc/imagemagick/copyright /usr/share/bug/imagemagick
    – shirish
    Aug 20, 2022 at 6:42
1

Given that the format is jpg it is possible to define the maximum file size:

convert shirish.jpg -define jpeg:extent=20k shirish-20k.jpg

That is almost certain to degrade the quality of your image too much.

But it is worth knowing.

Link to description

1
  • Thank you for that, will try that as well :)
    – shirish
    Aug 22, 2022 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.