Fit: unsupported JPEG feature


I have a problem with my shortcode on at least on of my photos.
The error I get is:

Error: error building site: "+PathToMyWebsiteSource+/content/post/myComputer20231119/": failed to render shortcode "imgwebp": failed to process shortcode: "+PathToMyWebsiteSource+/layouts/shortcodes/imgwebp.html:7:8": execute of template failed: template: shortcodes/imgwebp.html:7:8: executing "shortcodes/imgwebp.html" at <.Fit>: error calling Fit: image "+PathToMyWebsiteSource+/content/post/myComputer20231119/DSC_0305_upload.JPG": fit : unsupported JPEG feature: unknown marker

The source code of my shortcode is:

{{ $imgPath := .Get "src" }}
{{ $altText := .Get "alt" }}
{{ $width := .Get "width" | default "800" | int}}
{{ $height := .Get "height" | default "600" | int}}

{{ with .Page.Resources.Get $imgPath }}
{{ with .Fit (printf "%dx%d webp" $width $height) }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
{{ end }}
{{ end }}

I checked the file with Linux and it is a JPEG…

file DSC_0305_upload.JPG 
DSC_0305_upload.JPG: JPEG image data, JFIF standard 1.01, resolution (DPI), density 300x300, segment length 16, Exif Standard: [TIFF image data, little-endian, direntries=12, description=                                    , manufacturer=NIKON CORPORATION, model=NIKON D5100, orientation=upper-left, xresolution=226, yresolution=234, resolutionunit=2, software=GIMP 2.10.28, datetime=2021:12:12 17:36:17, GPS-Data], comment: "                                    +My Full Name+"

hugo env
hugo v0.120.1+extended linux/amd64 BuildDate=unknown

Any idea how to fix it?

There’s at least one known issue with Go’s image decoder when using images generated by GIMP. Without access to your image it’s impossible to say to say whether this is the same problem.

I would take the image for a roundtrip through ImageMagick (convert) or similar.

1 Like

here is an upload of the Image

I am unable to view this file using:

  • Adobe Fireworks (CS5)
  • Adobe Photoshop (CS5)
  • Chrome (v119.0.6045.159)
  • Edge (v119.0.2151.72)
  • Eye of GNOME (v42.0)
  • Firefox (v119.0.1)
  • Opera (v105.0.4970.16)
  • Visual Studio Code (v1.84.2)

So I would classify this problem as file corruption, not a software defect.

If you have installed ImageMagick this will cleanup the file:

convert DSC_0305_upload.JPG fixed.jpg

If you are the one using GIMP, look for and disable the “use arithmetic coding” option.

So I would classify this problem as file corruption, not a software defect.

I can open it with Geeqie, feh, Shotwell, ida, GimP and it is my Wallpaper on cinnamon desktop. Also the cloud provider Tuxedo can render it to the browser with NextCloud.

The file looks okay to the jpeg tools:

jpeginfo -c DSC_0305_upload.JPG
DSC_0305_upload.JPG              3437 x 1430 24bit P JFIF,Exif,XMP,ICC,IPTC,COM 1912867 OK

ImageMagick also does not see any corruption on the file and returns with 0:

identify -verbose -regard-warnings DSC_0305_upload.JPG; echo $?
  Filename: DSC_0305_upload.JPG
  Permissions: rw-r--r--
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 3437x1430+0+0
  Resolution: 300x300
  Print size: 11.4567x4.76667
  Units: PixelsPerInch
  Colorspace: sRGB
  Type: TrueColor
  Base type: Undefined
  Endianness: Undefined
  Depth: 8-bit
  Channels: 3.0
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 4914910
      min: 6  (0.0235294)
      max: 255 (1)
      mean: 115.372 (0.452439)
      median: 130 (0.509804)
      standard deviation: 35.887 (0.140733)
      kurtosis: -0.232982
      skewness: -0.946037
      entropy: 0.820977
      min: 12  (0.0470588)
      max: 255 (1)
      mean: 116.623 (0.457345)
      median: 134 (0.52549)
      standard deviation: 37.4112 (0.146711)
      kurtosis: -0.316118
      skewness: -0.98433
      entropy: 0.797145
      min: 0  (0)
      max: 250 (0.980392)
      mean: 120.029 (0.4707)
      median: 140 (0.54902)
      standard deviation: 39.7586 (0.155916)
      kurtosis: -0.237452
      skewness: -1.04101
      entropy: 0.785422
  Image statistics:
      min: 0  (0)
      max: 255 (1)
      mean: 117.341 (0.460161)
      median: 134.667 (0.528105)
      standard deviation: 37.6856 (0.147787)
      kurtosis: -0.274367
      skewness: -0.980861
      entropy: 0.801181
  Rendering intent: Perceptual
  Gamma: 0.454545
    red primary: (0.64,0.33,0.03)
    green primary: (0.3,0.6,0.1)
    blue primary: (0.15,0.06,0.79)
    white point: (0.3127,0.329,0.3583)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: black
  Interlace: JPEG
  Intensity: Undefined
  Compose: Over
  Page geometry: 3437x1430+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 100
  Orientation: TopLeft
    Profile-8bim: 42 bytes
    Profile-exif: 16660 bytes
    Profile-icc: 672 bytes
    Profile-iptc: 29 bytes
      Created Date[2,55]: 20211212
      Created Time[2,60]: 173617-1736
    Profile-xmp: 3160 bytes
    comment:                                     Frank Tornack
    date:create: 2023-11-19T16:12:29+00:00
    date:modify: 2023-11-19T15:40:41+00:00
    date:timestamp: 2023-11-19T16:29:31+00:00
    exif:ColorSpace: 1, 
    exif:ComponentsConfiguration: ...
    exif:CompressedBitsPerPixel: 4/1
    exif:Contrast: 0, 
    exif:CustomRendered: 0, 
    exif:DateTime: 2021:12:12 17:36:17
    exif:DateTimeDigitized: 2021:12:12 16:47:12
    exif:DateTimeOriginal: 2021:12:12 16:47:12
    exif:DigitalZoomRatio: 1/1
    exif:ExifOffset: 276, 
    exif:ExifVersion: 0230
    exif:ExposureBiasValue: 0/6
    exif:ExposureMode: 0, 
    exif:ExposureProgram: 0, 
    exif:ExposureTime: 10/600
    exif:FileSource: .
    exif:Flash: 16, 
    exif:FlashPixVersion: 0100
    exif:FNumber: 53/10
    exif:FocalLength: 660/10
    exif:FocalLengthIn35mmFilm: 99, 
    exif:GainControl: 1, 
    exif:GPSInfo: 13096, 
    exif:GPSVersionID: ....
    exif:LightSource: 0, 
    exif:MakerNote: Nikon
    exif:MaxApertureValue: 48/10
    exif:MeteringMode: 5, 
    exif:Model: NIKON D5100
    exif:PhotographicSensitivity: 450, 
    exif:PixelXDimension: 4928, 
    exif:PixelYDimension: 3264, 
    exif:Saturation: 0, 
    exif:SceneCaptureType: 0, 
    exif:SceneType: .
    exif:SensingMethod: 2, 
    exif:SensitivityType: 2, 
    exif:Sharpness: 0, 
    exif:Software: GIMP 2.10.28
    exif:SubjectDistanceRange: 0, 
    exif:SubSecTime: 00
    exif:SubSecTimeDigitized: 00
    exif:SubSecTimeOriginal: 00
    exif:thumbnail:BitsPerSample: 8, 
    exif:thumbnail:Compression: 6, 
    exif:thumbnail:ImageLength: 106, 
    exif:thumbnail:ImageWidth: 256, 
    exif:thumbnail:JPEGInterchangeFormat: 13234, 
    exif:thumbnail:JPEGInterchangeFormatLength: 3420, 
    exif:thumbnail:PhotometricInterpretation: 6, 
    exif:thumbnail:SamplesPerPixel: 3, 
    exif:WhiteBalance: 0, 
    exif:YCbCrPositioning: 2, 
    icc:copyright: Public Domain
    icc:description: GIMP built-in sRGB
    icc:manufacturer: GIMP
    icc:model: sRGB
    jpeg:arithmetic-coding: true
    jpeg:colorspace: 2
    jpeg:sampling-factor: 1x1,1x1,1x1
    signature: d92464a26c55ae49e8ad5866a515e0c25b64c8efb54b02068be9bdb48e31fa94
    unknown: 1, 
    verbose: true
  Tainted: False
  Filesize: 1.82425MiB
  Number pixels: 4.91491M
  Pixel cache type: Memory
  Pixels per second: 11.1326MP
  User time: 0.440u
  Elapsed time: 0:01.441
  Version: ImageMagick 7.1.1-21 Q16-HDRI x86_64 21667

Arithmetic encoding was patent-encumbered for a while, so mainstream JPEG decoders just said, “No.”

So, while technically not a corrupt file, it might as well be.

Chromium’s position:

Status: WontFix (Closed)

Mozilla’s position:


1 Like

Chromium, as a friend of Google, will always want to push its own formats such as webp. From my point of view, this is unfortunately not an argument.

But maybe there is a suggestion on how to extend a shortcode… so that at least the build doesn’t break off completely. So please don’t set it to Close.

You could bypass image processing and throw a warning on every image from GIMP, but you cannot narrow that down to arithmetic encoded images.

Again, if you are the one processing images with GIMP, disable arithmetic coding. With a virgin installation of GIMP, arithmetic coding is disabled by default.

I was not for some weeks… se your “Mozilla’s position” link.

Is there something like try except in shortcodes?

No, there is not.

There’s a related proposal:

And a PR that was closed due to lack of activity (I just re-opened it):

With that PR, you could do something like this:

{{ with try (.Resize "200x") }}
  {{ with .Err }}
    {{ warnf "%s" . }}
  {{ else }}
    {{ with .Value }}
      <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
    {{ end }}
  {{ end }}
{{ end }}

Other than an extraneous fmt.Println in the PR, it seems to work as expected.