XF 2.2 Why are PNG format avatars being saved with JPG extensions?

eva2000

Well-known member
I'm looking at batch optimizing XF 2.2 avatar images if they're over a certain size using ImageMagick. But I just noticed that PNG format uploaded avatar images are being saved by the Xenforo system with JPG extensions?

When I download the avatar image and open it in my image viewer, it also complains wrong extension format and that it's not a JPG image and prompts me to rename it to PNG extension.

Using ImageMagick identify clearly shows uploaded avatar was an PNG image and not a JPG that Xenforo system has named the image file's extension
Bash:
identify data/avatars/m/0/1.jpg
data/avatars/m/0/1.jpg PNG 96x96 96x96+0+0 8-bit sRGB 4214B 0.000u 0:00.000

Seems the question was brought up with Resource Manager uploaded images too in the past https://xenforo.com/community/threads/resource-icons-as-png-stored-as-jpg.192103/ as well.
 

eva2000

Well-known member
Ok so I found @Chris D old post - so any image uploaded as avatar gets saved with JPG extension regardless and relies on web browser's inspection of the image metadata to determine image format.

There is no actual conversion of the data in this case. If you upload a jpg file, it will still be a jpg file, but it will just give it a png extension. This is actually sort of similar to how we process avatars - any avatar you upload will be given a .jpg extension.

So I updated my image optimizer to inspect the image format rather than extension to determine which tools to apply to optimize the image format. Here are Xenforo avatars as avif, webp, and jpg extension suffixed png named based on tool applied so I can compare image sizes

As the original .jpg files are in fact PNG files, opting and pngquant were applied to them
Bash:
./xf-avatar-optimizer.sh list
nginx  nginx  982     Jan  23  22:41  /data/avatars/s/0/2.webp
nginx  nginx  1629    Jan  23  22:41  /data/avatars/s/0/2.jpg.pngquant
nginx  nginx  4128    Jan  23  09:04  /data/avatars/s/0/2.jpg.optipng
nginx  nginx  4625    Jan  23  22:41  /data/avatars/s/0/2.jpg.opt
nginx  nginx  4648    Jan  22  23:32  /data/avatars/s/0/2.jpg
nginx  nginx  1437    Jan  23  22:41  /data/avatars/s/0/2.avif
nginx  nginx  570     Jan  23  22:41  /data/avatars/s/0/1.webp
nginx  nginx  730     Jan  23  22:41  /data/avatars/s/0/1.jpg.pngquant
nginx  nginx  1488    Jan  23  09:04  /data/avatars/s/0/1.jpg.optipng
nginx  nginx  1788    Jan  23  22:41  /data/avatars/s/0/1.jpg.opt
nginx  nginx  1809    Jan  17  11:52  /data/avatars/s/0/1.jpg
nginx  nginx  1007    Jan  23  22:41  /data/avatars/s/0/1.avif
nginx  nginx  9546    Jan  23  22:41  /data/avatars/o/0/2.webp
nginx  nginx  25234   Jan  23  22:41  /data/avatars/o/0/2.jpg.pngquant
nginx  nginx  112717  Jan  23  09:04  /data/avatars/o/0/2.jpg.optipng
nginx  nginx  127125  Jan  23  22:41  /data/avatars/o/0/2.jpg.opt
nginx  nginx  127102  Jan  22  23:32  /data/avatars/o/0/2.jpg
nginx  nginx  9407    Jan  23  22:41  /data/avatars/o/0/2.avif
nginx  nginx  1142    Jan  23  22:41  /data/avatars/o/0/1.webp
nginx  nginx  1169    Jan  23  22:41  /data/avatars/o/0/1.jpg.pngquant
nginx  nginx  2065    Jan  23  09:04  /data/avatars/o/0/1.jpg.optipng
nginx  nginx  2092    Jan  23  22:41  /data/avatars/o/0/1.jpg.opt
nginx  nginx  2087    Jan  17  11:52  /data/avatars/o/0/1.jpg
nginx  nginx  1270    Jan  23  22:41  /data/avatars/o/0/1.avif
nginx  nginx  2184    Jan  23  22:41  /data/avatars/m/0/2.webp
nginx  nginx  3542    Jan  23  22:41  /data/avatars/m/0/2.jpg.pngquant
nginx  nginx  12178   Jan  23  09:04  /data/avatars/m/0/2.jpg.optipng
nginx  nginx  13601   Jan  23  22:41  /data/avatars/m/0/2.jpg.opt
nginx  nginx  13634   Jan  22  23:32  /data/avatars/m/0/2.jpg
nginx  nginx  2672    Jan  23  22:41  /data/avatars/m/0/2.avif
nginx  nginx  934     Jan  23  22:41  /data/avatars/m/0/1.webp
nginx  nginx  1232    Jan  23  22:41  /data/avatars/m/0/1.jpg.pngquant
nginx  nginx  3351    Jan  23  09:04  /data/avatars/m/0/1.jpg.optipng
nginx  nginx  4193    Jan  23  22:41  /data/avatars/m/0/1.jpg.opt
nginx  nginx  4214    Jan  17  11:52  /data/avatars/m/0/1.jpg
nginx  nginx  1448    Jan  23  22:41  /data/avatars/m/0/1.avif
nginx  nginx  4592    Jan  23  22:41  /data/avatars/l/0/2.webp
nginx  nginx  8683    Jan  23  22:41  /data/avatars/l/0/2.jpg.pngquant
nginx  nginx  36771   Jan  23  09:04  /data/avatars/l/0/2.jpg.optipng
nginx  nginx  41347   Jan  23  22:41  /data/avatars/l/0/2.jpg.opt
nginx  nginx  41411   Jan  22  23:32  /data/avatars/l/0/2.jpg
nginx  nginx  5042    Jan  23  22:41  /data/avatars/l/0/2.avif
nginx  nginx  1734    Jan  23  22:41  /data/avatars/l/0/1.webp
nginx  nginx  2512    Jan  23  22:41  /data/avatars/l/0/1.jpg.pngquant
nginx  nginx  7403    Jan  23  09:04  /data/avatars/l/0/1.jpg.optipng
nginx  nginx  9375    Jan  23  22:41  /data/avatars/l/0/1.jpg.opt
nginx  nginx  9410    Jan  17  11:52  /data/avatars/l/0/1.jpg
nginx  nginx  2408    Jan  23  22:41  /data/avatars/l/0/1.avif
nginx  nginx  9694    Jan  23  22:41  /data/avatars/h/0/2.webp
nginx  nginx  23463   Jan  23  22:41  /data/avatars/h/0/2.jpg.pngquant
nginx  nginx  110569  Jan  23  09:04  /data/avatars/h/0/2.jpg.optipng
nginx  nginx  124695  Jan  23  22:41  /data/avatars/h/0/2.jpg.opt
nginx  nginx  124820  Jan  22  23:32  /data/avatars/h/0/2.jpg
nginx  nginx  9318    Jan  23  22:41  /data/avatars/h/0/2.avif
nginx  nginx  3972    Jan  23  22:41  /data/avatars/h/0/1.webp
nginx  nginx  3802    Jan  23  22:41  /data/avatars/h/0/1.jpg.pngquant
nginx  nginx  11459   Jan  23  09:04  /data/avatars/h/0/1.jpg.optipng
nginx  nginx  13184   Jan  23  22:41  /data/avatars/h/0/1.jpg.opt
nginx  nginx  13218   Jan  17  11:52  /data/avatars/h/0/1.jpg
nginx  nginx  4580    Jan  23  22:41  /data/avatars/h/0/1.avif
 
Top